Use correct share upload url (#1863)
This commit is contained in:
committed by
Harshavardhana
parent
6de2b4559e
commit
b9f1950320
+2
-2
@@ -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",
|
||||
})
|
||||
|
||||
+10
-7
@@ -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
|
||||
}
|
||||
|
||||
+1
-1
@@ -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)
|
||||
|
||||
@@ -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>" // 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,
|
||||
|
||||
Reference in New Issue
Block a user