diff --git a/weed/s3api/filer_multipart.go b/weed/s3api/filer_multipart.go index 0739b2220..eb3daf220 100644 --- a/weed/s3api/filer_multipart.go +++ b/weed/s3api/filer_multipart.go @@ -39,7 +39,7 @@ func (s3a *S3ApiServer) createMultipartUpload(ctx context.Context, input *s3.Cre output = &InitiateMultipartUploadResult{ CreateMultipartUploadOutput: s3.CreateMultipartUploadOutput{ Bucket: input.Bucket, - Key: input.Key, + Key: objectKey(input.Key), UploadId: aws.String(uploadIdString), }, } @@ -102,7 +102,7 @@ func (s3a *S3ApiServer) completeMultipartUpload(ctx context.Context, input *s3.C CompleteMultipartUploadOutput: s3.CompleteMultipartUploadOutput{ Bucket: input.Bucket, ETag: aws.String("\"" + filer2.ETag(finalParts) + "\""), - Key: input.Key, + Key: objectKey(input.Key), }, } @@ -159,7 +159,7 @@ func (s3a *S3ApiServer) listMultipartUploads(ctx context.Context, input *s3.List if entry.Extended != nil { key := entry.Extended["key"] output.Uploads = append(output.Uploads, &s3.MultipartUpload{ - Key: aws.String(string(key)), + Key: objectKey(aws.String(string(key))), UploadId: aws.String(entry.Name), }) } @@ -177,7 +177,7 @@ func (s3a *S3ApiServer) listObjectParts(ctx context.Context, input *s3.ListParts output = &ListPartsResult{ ListPartsOutput: s3.ListPartsOutput{ Bucket: input.Bucket, - Key: input.Key, + Key: objectKey(input.Key), UploadId: input.UploadId, MaxParts: input.MaxParts, // the maximum number of parts to return. PartNumberMarker: input.PartNumberMarker, // the part number starts after this, exclusive diff --git a/weed/s3api/filer_util.go b/weed/s3api/filer_util.go index 4f2c1578b..84e3050cd 100644 --- a/weed/s3api/filer_util.go +++ b/weed/s3api/filer_util.go @@ -4,6 +4,7 @@ import ( "context" "fmt" "os" + "strings" "time" "github.com/chrislusf/seaweedfs/weed/glog" @@ -143,3 +144,11 @@ func (s3a *S3ApiServer) exists(ctx context.Context, parentDirectoryPath string, return } + +func objectKey(key *string) *string { + if strings.HasPrefix(*key, "/") { + t := (*key)[1:] + return &t + } + return key +} \ No newline at end of file diff --git a/weed/s3api/s3api_object_multipart_handlers.go b/weed/s3api/s3api_object_multipart_handlers.go index 47f83a264..72a25e4a5 100644 --- a/weed/s3api/s3api_object_multipart_handlers.go +++ b/weed/s3api/s3api_object_multipart_handlers.go @@ -28,7 +28,7 @@ func (s3a *S3ApiServer) NewMultipartUploadHandler(w http.ResponseWriter, r *http response, errCode := s3a.createMultipartUpload(context.Background(), &s3.CreateMultipartUploadInput{ Bucket: aws.String(bucket), - Key: aws.String(object), + Key: objectKey(aws.String(object)), }) if errCode != ErrNone { @@ -53,7 +53,7 @@ func (s3a *S3ApiServer) CompleteMultipartUploadHandler(w http.ResponseWriter, r response, errCode := s3a.completeMultipartUpload(context.Background(), &s3.CompleteMultipartUploadInput{ Bucket: aws.String(bucket), - Key: aws.String(object), + Key: objectKey(aws.String(object)), UploadId: aws.String(uploadID), }) @@ -79,7 +79,7 @@ func (s3a *S3ApiServer) AbortMultipartUploadHandler(w http.ResponseWriter, r *ht response, errCode := s3a.abortMultipartUpload(context.Background(), &s3.AbortMultipartUploadInput{ Bucket: aws.String(bucket), - Key: aws.String(object), + Key: objectKey(aws.String(object)), UploadId: aws.String(uploadID), }) @@ -151,7 +151,7 @@ func (s3a *S3ApiServer) ListObjectPartsHandler(w http.ResponseWriter, r *http.Re response, errCode := s3a.listObjectParts(context.Background(), &s3.ListPartsInput{ Bucket: aws.String(bucket), - Key: aws.String(object), + Key: objectKey(aws.String(object)), MaxParts: aws.Int64(int64(maxParts)), PartNumberMarker: aws.Int64(int64(partNumberMarker)), UploadId: aws.String(uploadID), diff --git a/weed/s3api/s3api_objects_list_handlers.go b/weed/s3api/s3api_objects_list_handlers.go index fd20ebe3c..4053913fb 100644 --- a/weed/s3api/s3api_objects_list_handlers.go +++ b/weed/s3api/s3api_objects_list_handlers.go @@ -7,6 +7,7 @@ import ( "net/url" "path/filepath" "strconv" + "strings" "time" "github.com/chrislusf/seaweedfs/weed/filer2" @@ -91,6 +92,9 @@ func (s3a *S3ApiServer) listFilerEntries(ctx context.Context, bucket, originalPr // convert full path prefix into directory name and prefix for entry name dir, prefix := filepath.Split(originalPrefix) + if strings.HasPrefix(dir, "/") { + dir = dir[1:] + } // check filer err = s3a.withFilerClient(ctx, func(client filer_pb.SeaweedFilerClient) error {