Skip to content

Commit 607d94f

Browse files
authored
add encoded filename as part of upload url (#3140)
1 parent 83b060e commit 607d94f

File tree

3 files changed

+37
-27
lines changed

3 files changed

+37
-27
lines changed

integration/user_api_bucket_test.go

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ package integration
2121
import (
2222
"bytes"
2323
"context"
24+
"encoding/base64"
2425
"encoding/json"
2526
"errors"
2627
"fmt"
@@ -395,9 +396,10 @@ func UploadAnObject(bucketName, fileName string) (*http.Response, error) {
395396
contentType + boundaryEnd
396397
arrayOfBytes := []byte(file)
397398
requestDataBody := bytes.NewReader(arrayOfBytes)
399+
apiURL := "http://localhost:9090/api/v1/buckets/" + bucketName + "/objects/upload" + "?prefix=" + base64.StdEncoding.EncodeToString([]byte(fileName))
398400
request, err := http.NewRequest(
399401
"POST",
400-
"http://localhost:9090/api/v1/buckets/"+bucketName+"/objects/upload",
402+
apiURL,
401403
requestDataBody,
402404
)
403405
if err != nil {
@@ -488,9 +490,11 @@ func PutObjectsRetentionStatus(bucketName, prefix, versionID, mode, expires stri
488490
}
489491
requestDataJSON, _ := json.Marshal(requestDataAdd)
490492
requestDataBody := bytes.NewReader(requestDataJSON)
493+
apiURL := "http://localhost:9090/api/v1/buckets/" + bucketName + "/objects/retention?prefix=" + prefix + "&version_id=" + versionID
494+
491495
request, err := http.NewRequest(
492496
"PUT",
493-
"http://localhost:9090/api/v1/buckets/"+bucketName+"/objects/retention?prefix="+prefix+"&version_id="+versionID,
497+
apiURL,
494498
requestDataBody,
495499
)
496500
if err != nil {
@@ -726,9 +730,10 @@ func PutObjectsLegalholdStatus(bucketName, prefix, status, versionID string) (*h
726730
}
727731
requestDataJSON, _ := json.Marshal(requestDataAdd)
728732
requestDataBody := bytes.NewReader(requestDataJSON)
733+
apiURL := "http://localhost:9090/api/v1/buckets/" + bucketName + "/objects/legalhold?prefix=" + prefix + "&version_id=" + versionID
729734
request, err := http.NewRequest(
730735
"PUT",
731-
"http://localhost:9090/api/v1/buckets/"+bucketName+"/objects/legalhold?prefix="+prefix+"&version_id="+versionID,
736+
apiURL,
732737
requestDataBody,
733738
)
734739
if err != nil {
@@ -747,8 +752,8 @@ func TestPutObjectsLegalholdStatus(t *testing.T) {
747752
// Variables
748753
assert := assert.New(t)
749754
bucketName := "testputobjectslegalholdstatus"
750-
fileName := "testputobjectslegalholdstatus.txt"
751-
prefix := "dGVzdHB1dG9iamVjdHNsZWdhbGhvbGRzdGF0dXMudHh0" // encoded base64
755+
objName := "testputobjectslegalholdstatus.txt" // // encoded base64 of testputobjectslegalholdstatus.txt = dGVzdHB1dG9iamVjdHNsZWdhbGhvbGRzdGF0dXMudHh0
756+
objectNameEncoded := "dGVzdHB1dG9iamVjdHNsZWdhbGhvbGRzdGF0dXMudHh0"
752757
status := "enabled"
753758

754759
// 1. Create bucket
@@ -759,7 +764,7 @@ func TestPutObjectsLegalholdStatus(t *testing.T) {
759764
// 2. Add object
760765
uploadResponse, uploadError := UploadAnObject(
761766
bucketName,
762-
fileName,
767+
objName,
763768
)
764769
assert.Nil(uploadError)
765770
if uploadError != nil {
@@ -776,7 +781,7 @@ func TestPutObjectsLegalholdStatus(t *testing.T) {
776781
}
777782

778783
// Get versionID
779-
listResponse, _ := ListObjects(bucketName, prefix, "true")
784+
listResponse, _ := ListObjects(bucketName, "", "true")
780785
bodyBytes, _ := io.ReadAll(listResponse.Body)
781786
listObjs := models.ListObjectsResponse{}
782787
err := json.Unmarshal(bodyBytes, &listObjs)
@@ -814,7 +819,7 @@ func TestPutObjectsLegalholdStatus(t *testing.T) {
814819
// 3. Put Objects Legal Status
815820
putResponse, putError := PutObjectsLegalholdStatus(
816821
bucketName,
817-
prefix,
822+
objectNameEncoded,
818823
status,
819824
tt.args.versionID,
820825
)

portal-ui/src/screens/Console/Buckets/ListBuckets/Objects/ListObjects/ListObjects.tsx

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,8 @@ const ListObjects = () => {
522522
relativeFolderPath = fileWebkitRelativePath;
523523
}
524524

525+
let prefixPath = "";
526+
525527
if (path !== "" || relativeFolderPath !== "") {
526528
const finalFolderPath = relativeFolderPath
527529
.split("/")
@@ -530,26 +532,30 @@ const ListObjects = () => {
530532

531533
const pathClean = path.endsWith("/") ? path.slice(0, -1) : path;
532534

533-
encodedPath = encodeURLString(
534-
`${pathClean}${
535-
!pathClean.endsWith("/") &&
536-
finalFolderPath !== "" &&
537-
!finalFolderPath.startsWith("/")
538-
? "/"
539-
: ""
540-
}${finalFolderPath}${
541-
!finalFolderPath.endsWith("/") ||
542-
(finalFolderPath.trim() === "" && !path.endsWith("/"))
543-
? "/"
544-
: ""
545-
}`,
546-
);
535+
prefixPath = `${pathClean}${
536+
!pathClean.endsWith("/") &&
537+
finalFolderPath !== "" &&
538+
!finalFolderPath.startsWith("/")
539+
? "/"
540+
: ""
541+
}${finalFolderPath}${
542+
!finalFolderPath.endsWith("/") ||
543+
(finalFolderPath.trim() === "" && !path.endsWith("/"))
544+
? "/"
545+
: ""
546+
}`;
547547
}
548548

549-
if (encodedPath !== "") {
550-
uploadUrl = `${uploadUrl}?prefix=${encodedPath}`;
549+
if (prefixPath !== "") {
550+
uploadUrl = `${uploadUrl}?prefix=${encodeURLString(
551+
prefixPath + fileName,
552+
)}`;
553+
} else {
554+
uploadUrl = `${uploadUrl}?prefix=${encodeURLString(fileName)}`;
551555
}
552556

557+
encodedPath = encodeURLString(prefixPath);
558+
553559
const identity = encodeURLString(
554560
`${bucketName}-${encodedPath}-${new Date().getTime()}-${Math.random()}`,
555561
);

restapi/user_objects.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import (
2424
"io"
2525
"net/http"
2626
"net/url"
27-
"path"
2827
"path/filepath"
2928
"regexp"
3029
"strconv"
@@ -1030,8 +1029,8 @@ func uploadFiles(ctx context.Context, client MinioClient, params objectApi.PostB
10301029
if contentType == "" {
10311030
contentType = mimedb.TypeByExtension(filepath.Ext(p.FileName()))
10321031
}
1033-
1034-
_, err = client.putObject(ctx, params.BucketName, path.Join(prefix, path.Clean(p.FileName())), p, size, minio.PutObjectOptions{
1032+
objectName := prefix // prefix will have complete object path e.g: /test-prefix/test-object.txt
1033+
_, err = client.putObject(ctx, params.BucketName, objectName, p, size, minio.PutObjectOptions{
10351034
ContentType: contentType,
10361035
DisableMultipart: true, // Do not upload as multipart stream for console uploader.
10371036
})

0 commit comments

Comments
 (0)