add encoded filename as part of upload url (#3140)
This commit is contained in:
committed by
GitHub
parent
83b060ef94
commit
607d94fef4
@@ -21,6 +21,7 @@ package integration
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/base64"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
@@ -395,9 +396,10 @@ func UploadAnObject(bucketName, fileName string) (*http.Response, error) {
|
||||
contentType + boundaryEnd
|
||||
arrayOfBytes := []byte(file)
|
||||
requestDataBody := bytes.NewReader(arrayOfBytes)
|
||||
apiURL := "http://localhost:9090/api/v1/buckets/" + bucketName + "/objects/upload" + "?prefix=" + base64.StdEncoding.EncodeToString([]byte(fileName))
|
||||
request, err := http.NewRequest(
|
||||
"POST",
|
||||
"http://localhost:9090/api/v1/buckets/"+bucketName+"/objects/upload",
|
||||
apiURL,
|
||||
requestDataBody,
|
||||
)
|
||||
if err != nil {
|
||||
@@ -488,9 +490,11 @@ func PutObjectsRetentionStatus(bucketName, prefix, versionID, mode, expires stri
|
||||
}
|
||||
requestDataJSON, _ := json.Marshal(requestDataAdd)
|
||||
requestDataBody := bytes.NewReader(requestDataJSON)
|
||||
apiURL := "http://localhost:9090/api/v1/buckets/" + bucketName + "/objects/retention?prefix=" + prefix + "&version_id=" + versionID
|
||||
|
||||
request, err := http.NewRequest(
|
||||
"PUT",
|
||||
"http://localhost:9090/api/v1/buckets/"+bucketName+"/objects/retention?prefix="+prefix+"&version_id="+versionID,
|
||||
apiURL,
|
||||
requestDataBody,
|
||||
)
|
||||
if err != nil {
|
||||
@@ -726,9 +730,10 @@ func PutObjectsLegalholdStatus(bucketName, prefix, status, versionID string) (*h
|
||||
}
|
||||
requestDataJSON, _ := json.Marshal(requestDataAdd)
|
||||
requestDataBody := bytes.NewReader(requestDataJSON)
|
||||
apiURL := "http://localhost:9090/api/v1/buckets/" + bucketName + "/objects/legalhold?prefix=" + prefix + "&version_id=" + versionID
|
||||
request, err := http.NewRequest(
|
||||
"PUT",
|
||||
"http://localhost:9090/api/v1/buckets/"+bucketName+"/objects/legalhold?prefix="+prefix+"&version_id="+versionID,
|
||||
apiURL,
|
||||
requestDataBody,
|
||||
)
|
||||
if err != nil {
|
||||
@@ -747,8 +752,8 @@ func TestPutObjectsLegalholdStatus(t *testing.T) {
|
||||
// Variables
|
||||
assert := assert.New(t)
|
||||
bucketName := "testputobjectslegalholdstatus"
|
||||
fileName := "testputobjectslegalholdstatus.txt"
|
||||
prefix := "dGVzdHB1dG9iamVjdHNsZWdhbGhvbGRzdGF0dXMudHh0" // encoded base64
|
||||
objName := "testputobjectslegalholdstatus.txt" // // encoded base64 of testputobjectslegalholdstatus.txt = dGVzdHB1dG9iamVjdHNsZWdhbGhvbGRzdGF0dXMudHh0
|
||||
objectNameEncoded := "dGVzdHB1dG9iamVjdHNsZWdhbGhvbGRzdGF0dXMudHh0"
|
||||
status := "enabled"
|
||||
|
||||
// 1. Create bucket
|
||||
@@ -759,7 +764,7 @@ func TestPutObjectsLegalholdStatus(t *testing.T) {
|
||||
// 2. Add object
|
||||
uploadResponse, uploadError := UploadAnObject(
|
||||
bucketName,
|
||||
fileName,
|
||||
objName,
|
||||
)
|
||||
assert.Nil(uploadError)
|
||||
if uploadError != nil {
|
||||
@@ -776,7 +781,7 @@ func TestPutObjectsLegalholdStatus(t *testing.T) {
|
||||
}
|
||||
|
||||
// Get versionID
|
||||
listResponse, _ := ListObjects(bucketName, prefix, "true")
|
||||
listResponse, _ := ListObjects(bucketName, "", "true")
|
||||
bodyBytes, _ := io.ReadAll(listResponse.Body)
|
||||
listObjs := models.ListObjectsResponse{}
|
||||
err := json.Unmarshal(bodyBytes, &listObjs)
|
||||
@@ -814,7 +819,7 @@ func TestPutObjectsLegalholdStatus(t *testing.T) {
|
||||
// 3. Put Objects Legal Status
|
||||
putResponse, putError := PutObjectsLegalholdStatus(
|
||||
bucketName,
|
||||
prefix,
|
||||
objectNameEncoded,
|
||||
status,
|
||||
tt.args.versionID,
|
||||
)
|
||||
|
||||
@@ -522,6 +522,8 @@ const ListObjects = () => {
|
||||
relativeFolderPath = fileWebkitRelativePath;
|
||||
}
|
||||
|
||||
let prefixPath = "";
|
||||
|
||||
if (path !== "" || relativeFolderPath !== "") {
|
||||
const finalFolderPath = relativeFolderPath
|
||||
.split("/")
|
||||
@@ -530,26 +532,30 @@ const ListObjects = () => {
|
||||
|
||||
const pathClean = path.endsWith("/") ? path.slice(0, -1) : path;
|
||||
|
||||
encodedPath = encodeURLString(
|
||||
`${pathClean}${
|
||||
!pathClean.endsWith("/") &&
|
||||
finalFolderPath !== "" &&
|
||||
!finalFolderPath.startsWith("/")
|
||||
? "/"
|
||||
: ""
|
||||
}${finalFolderPath}${
|
||||
!finalFolderPath.endsWith("/") ||
|
||||
(finalFolderPath.trim() === "" && !path.endsWith("/"))
|
||||
? "/"
|
||||
: ""
|
||||
}`,
|
||||
);
|
||||
prefixPath = `${pathClean}${
|
||||
!pathClean.endsWith("/") &&
|
||||
finalFolderPath !== "" &&
|
||||
!finalFolderPath.startsWith("/")
|
||||
? "/"
|
||||
: ""
|
||||
}${finalFolderPath}${
|
||||
!finalFolderPath.endsWith("/") ||
|
||||
(finalFolderPath.trim() === "" && !path.endsWith("/"))
|
||||
? "/"
|
||||
: ""
|
||||
}`;
|
||||
}
|
||||
|
||||
if (encodedPath !== "") {
|
||||
uploadUrl = `${uploadUrl}?prefix=${encodedPath}`;
|
||||
if (prefixPath !== "") {
|
||||
uploadUrl = `${uploadUrl}?prefix=${encodeURLString(
|
||||
prefixPath + fileName,
|
||||
)}`;
|
||||
} else {
|
||||
uploadUrl = `${uploadUrl}?prefix=${encodeURLString(fileName)}`;
|
||||
}
|
||||
|
||||
encodedPath = encodeURLString(prefixPath);
|
||||
|
||||
const identity = encodeURLString(
|
||||
`${bucketName}-${encodedPath}-${new Date().getTime()}-${Math.random()}`,
|
||||
);
|
||||
|
||||
@@ -24,7 +24,6 @@ import (
|
||||
"io"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"strconv"
|
||||
@@ -1030,8 +1029,8 @@ func uploadFiles(ctx context.Context, client MinioClient, params objectApi.PostB
|
||||
if contentType == "" {
|
||||
contentType = mimedb.TypeByExtension(filepath.Ext(p.FileName()))
|
||||
}
|
||||
|
||||
_, err = client.putObject(ctx, params.BucketName, path.Join(prefix, path.Clean(p.FileName())), p, size, minio.PutObjectOptions{
|
||||
objectName := prefix // prefix will have complete object path e.g: /test-prefix/test-object.txt
|
||||
_, err = client.putObject(ctx, params.BucketName, objectName, p, size, minio.PutObjectOptions{
|
||||
ContentType: contentType,
|
||||
DisableMultipart: true, // Do not upload as multipart stream for console uploader.
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user