generateSignedDownloadURL generates a signed URL for downloading the asset.
(asset *database.Asset)
| 250 | |
| 251 | // generateSignedDownloadURL generates a signed URL for downloading the asset. |
| 252 | func (s *Server) generateSignedDownloadURL(asset *database.Asset) (string, error) { |
| 253 | // asset.Path is of the form "gs://<bucket>/<path>" |
| 254 | u, err := url.Parse(asset.Path) |
| 255 | if err != nil { |
| 256 | return "", err |
| 257 | } |
| 258 | |
| 259 | opts := &storage.SignedURLOptions{ |
| 260 | Scheme: storage.SigningSchemeV4, |
| 261 | Method: "GET", |
| 262 | Expires: time.Now().Add(15 * time.Minute), |
| 263 | } |
| 264 | |
| 265 | signedURL, err := s.admin.Assets.SignedURL(strings.TrimPrefix(u.Path, "/"), opts) |
| 266 | if err != nil { |
| 267 | return "", err |
| 268 | } |
| 269 | return signedURL, nil |
| 270 | } |
| 271 | |
| 272 | // newGCSUploadHeaders returns a map of headers to be used when generating a signed URL for uploading an asset to GCS. |
| 273 | // They are used to enforce a maximum asset size for uploads. |
no test coverage detected