Browse Source

s3: adjust object key

pull/1020/head
Chris Lu 6 years ago
parent
commit
62843991f2
  1. 8
      weed/s3api/filer_multipart.go
  2. 9
      weed/s3api/filer_util.go
  3. 8
      weed/s3api/s3api_object_multipart_handlers.go
  4. 4
      weed/s3api/s3api_objects_list_handlers.go

8
weed/s3api/filer_multipart.go

@ -39,7 +39,7 @@ func (s3a *S3ApiServer) createMultipartUpload(ctx context.Context, input *s3.Cre
output = &InitiateMultipartUploadResult{ output = &InitiateMultipartUploadResult{
CreateMultipartUploadOutput: s3.CreateMultipartUploadOutput{ CreateMultipartUploadOutput: s3.CreateMultipartUploadOutput{
Bucket: input.Bucket, Bucket: input.Bucket,
Key: input.Key,
Key: objectKey(input.Key),
UploadId: aws.String(uploadIdString), UploadId: aws.String(uploadIdString),
}, },
} }
@ -102,7 +102,7 @@ func (s3a *S3ApiServer) completeMultipartUpload(ctx context.Context, input *s3.C
CompleteMultipartUploadOutput: s3.CompleteMultipartUploadOutput{ CompleteMultipartUploadOutput: s3.CompleteMultipartUploadOutput{
Bucket: input.Bucket, Bucket: input.Bucket,
ETag: aws.String("\"" + filer2.ETag(finalParts) + "\""), 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 { if entry.Extended != nil {
key := entry.Extended["key"] key := entry.Extended["key"]
output.Uploads = append(output.Uploads, &s3.MultipartUpload{ output.Uploads = append(output.Uploads, &s3.MultipartUpload{
Key: aws.String(string(key)),
Key: objectKey(aws.String(string(key))),
UploadId: aws.String(entry.Name), UploadId: aws.String(entry.Name),
}) })
} }
@ -177,7 +177,7 @@ func (s3a *S3ApiServer) listObjectParts(ctx context.Context, input *s3.ListParts
output = &ListPartsResult{ output = &ListPartsResult{
ListPartsOutput: s3.ListPartsOutput{ ListPartsOutput: s3.ListPartsOutput{
Bucket: input.Bucket, Bucket: input.Bucket,
Key: input.Key,
Key: objectKey(input.Key),
UploadId: input.UploadId, UploadId: input.UploadId,
MaxParts: input.MaxParts, // the maximum number of parts to return. MaxParts: input.MaxParts, // the maximum number of parts to return.
PartNumberMarker: input.PartNumberMarker, // the part number starts after this, exclusive PartNumberMarker: input.PartNumberMarker, // the part number starts after this, exclusive

9
weed/s3api/filer_util.go

@ -4,6 +4,7 @@ import (
"context" "context"
"fmt" "fmt"
"os" "os"
"strings"
"time" "time"
"github.com/chrislusf/seaweedfs/weed/glog" "github.com/chrislusf/seaweedfs/weed/glog"
@ -143,3 +144,11 @@ func (s3a *S3ApiServer) exists(ctx context.Context, parentDirectoryPath string,
return return
} }
func objectKey(key *string) *string {
if strings.HasPrefix(*key, "/") {
t := (*key)[1:]
return &t
}
return key
}

8
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{ response, errCode := s3a.createMultipartUpload(context.Background(), &s3.CreateMultipartUploadInput{
Bucket: aws.String(bucket), Bucket: aws.String(bucket),
Key: aws.String(object),
Key: objectKey(aws.String(object)),
}) })
if errCode != ErrNone { if errCode != ErrNone {
@ -53,7 +53,7 @@ func (s3a *S3ApiServer) CompleteMultipartUploadHandler(w http.ResponseWriter, r
response, errCode := s3a.completeMultipartUpload(context.Background(), &s3.CompleteMultipartUploadInput{ response, errCode := s3a.completeMultipartUpload(context.Background(), &s3.CompleteMultipartUploadInput{
Bucket: aws.String(bucket), Bucket: aws.String(bucket),
Key: aws.String(object),
Key: objectKey(aws.String(object)),
UploadId: aws.String(uploadID), 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{ response, errCode := s3a.abortMultipartUpload(context.Background(), &s3.AbortMultipartUploadInput{
Bucket: aws.String(bucket), Bucket: aws.String(bucket),
Key: aws.String(object),
Key: objectKey(aws.String(object)),
UploadId: aws.String(uploadID), 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{ response, errCode := s3a.listObjectParts(context.Background(), &s3.ListPartsInput{
Bucket: aws.String(bucket), Bucket: aws.String(bucket),
Key: aws.String(object),
Key: objectKey(aws.String(object)),
MaxParts: aws.Int64(int64(maxParts)), MaxParts: aws.Int64(int64(maxParts)),
PartNumberMarker: aws.Int64(int64(partNumberMarker)), PartNumberMarker: aws.Int64(int64(partNumberMarker)),
UploadId: aws.String(uploadID), UploadId: aws.String(uploadID),

4
weed/s3api/s3api_objects_list_handlers.go

@ -7,6 +7,7 @@ import (
"net/url" "net/url"
"path/filepath" "path/filepath"
"strconv" "strconv"
"strings"
"time" "time"
"github.com/chrislusf/seaweedfs/weed/filer2" "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 // convert full path prefix into directory name and prefix for entry name
dir, prefix := filepath.Split(originalPrefix) dir, prefix := filepath.Split(originalPrefix)
if strings.HasPrefix(dir, "/") {
dir = dir[1:]
}
// check filer // check filer
err = s3a.withFilerClient(ctx, func(client filer_pb.SeaweedFilerClient) error { err = s3a.withFilerClient(ctx, func(client filer_pb.SeaweedFilerClient) error {

Loading…
Cancel
Save