Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 30 additions & 1 deletion storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func (c *Client) UploadOrUpdateFile(

// set content-type back to default after request
c.clientTransport.header.Set("content-type", "application/json")

if err != nil {
return FileUploadResponse{}, err
}
Expand Down Expand Up @@ -132,6 +132,35 @@ func (c *Client) CreateSignedUrl(bucketId string, filePath string, expiresIn int
return response, nil
}

// CreateSignedUrls create multiple signed URLs. Use a signed URL to share a file for a fixed amount of time.
// bucketId string The bucket id
// filePaths []string The file paths, including the file name. Should be of the format `folder/subfolder/filename.png`
// expiresIn int The number of seconds before the signed URLs expire. Defaults to 60 seconds.
func (c *Client) CreateSignedUrls(bucketId string, filePaths []string, expiresIn int) ([]SignedUrlResponse, error) {
signedURL := c.clientTransport.baseUrl.String() + "/object/sign/" + bucketId
jsonBody := map[string]interface{}{
"expiresIn": expiresIn,
"paths": filePaths,
}

req, err := c.NewRequest(http.MethodPost, signedURL, &jsonBody)
if err != nil {
return []SignedUrlResponse{}, err
}

var response []SignedUrlResponse
_, err = c.Do(req, &response)
if err != nil {
return []SignedUrlResponse{}, err
}

for i := range response {
response[i].SignedURL = c.clientTransport.baseUrl.String() + response[i].SignedURL
}

return response, nil
}

// CreateSignedUploadUrl create a signed URL for uploading a file. Use a signed URL to upload a file directly to a bucket.
// bucketId string The bucket id
// filePath path The file path, including the file name. Should be of the format `folder/subfolder/filename.png`
Expand Down
10 changes: 10 additions & 0 deletions test/fileupload_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,16 @@ func TestSignedUrl(t *testing.T) {
fmt.Println(resp, err)
}

func TestSignedUrls(t *testing.T) {
c := storage_go.NewClient(rawUrl, token, map[string]string{})
resp, err := c.CreateSignedUrls("test", []string{"file_example_MP4_480_1_5MG.mp4", "test.txt"}, 120)
if err != nil {
t.Fatalf("CreateSignedUrls failed: %v", err)
}

fmt.Println(resp, err)
}

func TestPublicUrl(t *testing.T) {
c := storage_go.NewClient(rawUrl, token, map[string]string{})
resp := c.GetPublicUrl("shield", "book.pdf")
Expand Down