2

Using javascript and AWS Amplify, I am trying to attach some custom metadata to files that are uploaded to my s3 bucket. Most of the available options are not described in the documentation, but after digging around the source code I found that adding, for example, {metadata: { 'your-custom-key-1': 'foo', 'your-custom-key-2': 'bar' } as the options paramter in Storage.put() will automatically create custom metadata on your file, which automatically prefixes your custom keys with 'x-amz-meta-'. So in the above case, you have 'x-amz-your-custom-key-1': 'foo', 'x-amz-your-custom-key-2': 'bar' as the actual metadata attached and saved to that specific files.

The issue is, as far as I can tell, I do not see any way to retrieve this metadata using amplify. I presume I would have to dig a layer deeper into the core s3 class to retrieve this information. To make matters even more confusing...I've found that with amplify, if I call Storage.get() with the hidden option { download: true} as my option parameter, I get back a response that actually has a Metadata key, however it is always empty, even when I certainly do have custom metadata attached to my file. I'm guessing this a feature that has either been changed or is incomplete? Looking into the core s3 class, I found the headObject, but I am not clear whether this would give me my custom metadata or just the default. My end goal is to list all of the associated metadata with all files in my bucket when I call Storage.list(). Thanks for any advice

Cauliflower
  • 446
  • 4
  • 12
  • Are you restricted to using metadata? Can you use tags instead? [Differences between metadata and tags](https://stackoverflow.com/questions/42126348/difference-between-object-tags-and-object-metadata) – Alexander Vitanov Jun 06 '18 at 16:07
  • it looks like 'tags' would work as well. I was really hoping to keep things simple using the amplify {Storage} class but I can't see any way to retrieve tags or metadata using options on the the Storage.list() method. It looks like this functionality simply doesn't exist in amplify and basically what I'm having trouble with is figuring out how I would list these tags or metadata for all the items in a directory even using the core s3 class. – Cauliflower Jun 06 '18 at 18:21
  • You can achieve it with [using aws nodejs sdk](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html#getObjectTagging-property) – Alexander Vitanov Jun 06 '18 at 18:30
  • @Pristique Thanks for mentioning the `download` hidden option. When I use that with Storage.get(), I do get back my custom header in the returned Metadata object. I'm using aws-amplify version 1.0.6, but I actually uploaded the s3 objects with the standard JavaScript SDK. I would very much prefer not to have to download all of the files though. As you mention, it would be great to have this with Storage.list(). – Joe Aug 31 '18 at 09:31
  • @Pristique Another thing to note is that you will need to add another ExposeHeader element to the bucket's CORS configuration for the custom header that you would like returned `x-amz-meta-my-custom-header` – Joe Aug 31 '18 at 12:36

0 Answers0