From b9f19503200e4c48c06500515565a587accd64e4 Mon Sep 17 00:00:00 2001 From: Anis Elleuch Date: Tue, 25 Oct 2016 21:23:22 +0100 Subject: [PATCH] Use correct share upload url (#1863) --- cmd/client-fs.go | 4 ++-- cmd/client-s3.go | 17 ++++++++++------- cmd/client.go | 2 +- cmd/share-upload-main.go | 16 +++++++--------- 4 files changed, 20 insertions(+), 19 deletions(-) diff --git a/cmd/client-fs.go b/cmd/client-fs.go index 257c3211..e7cba5fa 100644 --- a/cmd/client-fs.go +++ b/cmd/client-fs.go @@ -352,8 +352,8 @@ func (f *fsClient) ShareDownload(expires time.Duration) (string, *probe.Error) { } // ShareUpload - share upload not implemented for filesystem. -func (f *fsClient) ShareUpload(startsWith bool, expires time.Duration, contentType string) (map[string]string, *probe.Error) { - return nil, probe.NewError(APINotImplemented{ +func (f *fsClient) ShareUpload(startsWith bool, expires time.Duration, contentType string) (string, map[string]string, *probe.Error) { + return "", nil, probe.NewError(APINotImplemented{ API: "ShareUpload", APIType: "filesystem", }) diff --git a/cmd/client-s3.go b/cmd/client-s3.go index bb9af3a9..06cb9af7 100644 --- a/cmd/client-s3.go +++ b/cmd/client-s3.go @@ -1474,28 +1474,31 @@ func (c *s3Client) ShareDownload(expires time.Duration) (string, *probe.Error) { } // ShareUpload - get data for presigned post http form upload. -func (c *s3Client) ShareUpload(isRecursive bool, expires time.Duration, contentType string) (map[string]string, *probe.Error) { +func (c *s3Client) ShareUpload(isRecursive bool, expires time.Duration, contentType string) (string, map[string]string, *probe.Error) { bucket, object := c.url2BucketAndObject() p := minio.NewPostPolicy() if e := p.SetExpires(time.Now().UTC().Add(expires)); e != nil { - return nil, probe.NewError(e) + return "", nil, probe.NewError(e) } if strings.TrimSpace(contentType) != "" || contentType != "" { // No need to verify for error here, since we have stripped out spaces. p.SetContentType(contentType) } if e := p.SetBucket(bucket); e != nil { - return nil, probe.NewError(e) + return "", nil, probe.NewError(e) } if isRecursive { if e := p.SetKeyStartsWith(object); e != nil { - return nil, probe.NewError(e) + return "", nil, probe.NewError(e) } } else { if e := p.SetKey(object); e != nil { - return nil, probe.NewError(e) + return "", nil, probe.NewError(e) } } - _, m, e := c.api.PresignedPostPolicy(p) - return m, probe.NewError(e) + u, m, e := c.api.PresignedPostPolicy(p) + if e != nil { + return "", nil, probe.NewError(e) + } + return u.String(), m, nil } diff --git a/cmd/client.go b/cmd/client.go index 1ad43e7d..8c4a6f85 100644 --- a/cmd/client.go +++ b/cmd/client.go @@ -57,7 +57,7 @@ type Client interface { // I/O operations with expiration ShareDownload(expires time.Duration) (string, *probe.Error) - ShareUpload(bool, time.Duration, string) (map[string]string, *probe.Error) + ShareUpload(bool, time.Duration, string) (string, map[string]string, *probe.Error) // Watch events Watch(params watchParams) (*watchObject, *probe.Error) diff --git a/cmd/share-upload-main.go b/cmd/share-upload-main.go index 5eb433fd..44cd62b8 100644 --- a/cmd/share-upload-main.go +++ b/cmd/share-upload-main.go @@ -109,12 +109,7 @@ func checkShareUploadSyntax(ctx *cli.Context) { } // makeCurlCmd constructs curl command-line. -func makeCurlCmd(key string, isRecursive bool, uploadInfo map[string]string) string { - URL := newClientURL(key) - postURL := URL.Scheme + URL.SchemeSeparator + URL.Host + string(URL.Separator) - if !isBucketVirtualStyle(URL.Host) { - postURL = postURL + uploadInfo["bucket"] - } +func makeCurlCmd(key, postURL string, isRecursive bool, uploadInfo map[string]string) (string, *probe.Error) { postURL += " " curlCommand := "curl " + postURL for k, v := range uploadInfo { @@ -131,7 +126,7 @@ func makeCurlCmd(key string, isRecursive bool, uploadInfo map[string]string) str curlCommand += fmt.Sprintf("-F key=%s ", key) // Object name. } curlCommand += "-F file=@" // File to upload. - return curlCommand + return curlCommand, nil } // save shared URL to disk. @@ -157,7 +152,7 @@ func doShareUploadURL(objectURL string, isRecursive bool, expiry time.Duration, } // Generate pre-signed access info. - uploadInfo, err := clnt.ShareUpload(isRecursive, expiry, contentType) + shareURL, uploadInfo, err := clnt.ShareUpload(isRecursive, expiry, contentType) if err != nil { return err.Trace(objectURL, "expiry="+expiry.String(), "contentType="+contentType) } @@ -166,7 +161,10 @@ func doShareUploadURL(objectURL string, isRecursive bool, expiry time.Duration, objectURL = clnt.GetURL().String() // Generate curl command. - curlCmd := makeCurlCmd(objectURL, isRecursive, uploadInfo) + curlCmd, err := makeCurlCmd(objectURL, shareURL, isRecursive, uploadInfo) + if err != nil { + return err.Trace(objectURL) + } printMsg(shareMesssage{ ObjectURL: objectURL,