Amplify-js: [Feature request] `Storage.get` to return headers, not just URL

Created on 23 Jun 2020  路  4Comments  路  Source: aws-amplify/amplify-js

Is your feature request related to a problem? Please describe.

In https://github.com/aws-amplify/amplify-js/discussions/6135, @mtakac wanted to check the headers of a file instead of downloading it, but we only expose the URL with Storage.get. it'd be nice to give the option to return headers (or just expose headers anyway if it is no cost to us)

Describe the solution you'd like

as above

Describe alternatives you've considered

add a Storage.head api? since it maps to the HTTP HEAD request

Storage feature-request

Most helpful comment

Just one small thing:

My use case is to check if the file is expired before I download it. At least for this case, it would be probably easier if the Storage.get would allow access to headers or at least some subset of headers. For example if the Storage.get response would return an object similar to what Storage.list returns. Maybe it could do so based on some optional parameter (eg. Storage.get(key: string, { includeHeaders?: boolean })) so there are no breaking changes in the public API of Storage.get.

Adding Storage.head is fine as well and might be useful in some cases, but in my scenario, this would still require me to do 2 separate calls which seems a bit redundant.

All 4 comments

Just one small thing:

My use case is to check if the file is expired before I download it. At least for this case, it would be probably easier if the Storage.get would allow access to headers or at least some subset of headers. For example if the Storage.get response would return an object similar to what Storage.list returns. Maybe it could do so based on some optional parameter (eg. Storage.get(key: string, { includeHeaders?: boolean })) so there are no breaking changes in the public API of Storage.get.

Adding Storage.head is fine as well and might be useful in some cases, but in my scenario, this would still require me to do 2 separate calls which seems a bit redundant.

I also think the functionality I described might already be implemented in Storage. Maybe it's just a problem of missing docs and not specific enough types. Seems like when I call Storage.get with { download: true } in its config, I am able to access all the data I need, but I cannot figure out what's the object returned by the call:

{
   "$metadata":{
      "httpStatusCode":200,
      "httpHeaders":{ ...  },
      "retries":0,
      "totalRetryDelay":0
   },
   "__type":"GetObjectOutput",
   "AcceptRanges":"bytes",
   "Body":{
      "_data":{
         "size":1177045,
         "offset":0,
         "blobId":"A231BCCC-1F1A-4804-959F-26308CD89513",
         "type":"image/jpeg",
         "name":"profilePicture.jpg",
         "__collector":{
         }
      }
   },
   "ContentLength":1177045,
   "ContentType":"image/jpeg",
   "ETag":"\"fc401a6a724935c4f7badde118db217c\"",
   "LastModified":"2020-06-02T17:11:33.000Z",
   "Metadata":{
   }
}

I am not sure if I understand what's happening here:

  1. What exactly is this object?
  2. Does this mean that the file was already downloaded?
  3. If yes, how do I convert it into blob?
  4. If no, how do I download it (in react-native)?

Im going to move this to the Amplify JS repo as this is an implementation we would need to add there first prior to providing documentation.

Storage.get() without download:true doesn't actually make a request. It just provides a presigned URL that you can load to get the file. This signed URL can also be parsed to capture the request headers generated by Amplify using SIG_V4. However again note that no service calls are made.

With download:true the file is downloaded by the Amplify itself and given to the client. The file is of blob type. Let us know if there is still request for a feature.

Was this page helpful?
0 / 5 - 0 ratings