Amplify-js: Don't force public/ and private/ prefixes for S3 keys

Created on 22 Feb 2018  路  8Comments  路  Source: aws-amplify/amplify-js

There should be a way to not use the public/ and private/<region>:<uuid>/ prefixes. This removes control from the developer.

I'm also confused as to why the region is included in the path. Does it have some sort of effect on how data is stored in S3?

Storage

Most helpful comment

Found a way to do this,

let result = await Storage.put('folderName/imageName.png', blob, {
  contentType: 'image/jpeg',
    customPrefix: {
       public:''
    }
 });

This saves the file in the root of the bucket, inside folder "folderName".

All 8 comments

@ffxsam public and private prefixes are used mainly for notation around the permission level you decide i.e. Storage.configure( { level: 'private' } ).

Also, the region actually isn't added by us, this is the Cognito Identity ID, so essentially the user ID, and it allows for a sort of multi tenancy among the private files, so think of it like /private/me/... kinda like a home directory type of thing.

If we didn't use public/private prefixes, it may be difficult for the rest of the storage library to interact or enforce permissions. I'm no exactly sure how we would easily enforce permissions if we didn't use the prefix in S3, since S3 is object storage, the prefix allows us to easily enforce this permission. Let me know what you think.

Ahh, I guess I'm not informed on what the bigger picture of this library will be and how all the pieces fit together. I was under the impression that Amplify is basically a high-level wrapper around Cognito and related services. Is there something else in the library that depends on S3 storage using the prefixes like that?

Can you make the prefixes configurable? This would make life easier for existing projects.

I think making them configurable would be a pretty simple thing here, @ffxsam would this help in your use case?

Very much so, yes! I think locking people in to using /public and /private/{region}:{uuid} folders is probably not a good idea. We need flexibility & configurability.

Great, I'll add this to our backlog.

@mlabieniec @ffxsam Hi guys, how can i save files in the root of the bucket? I don't need prefix at all.

Found a way to do this,

let result = await Storage.put('folderName/imageName.png', blob, {
  contentType: 'image/jpeg',
    customPrefix: {
       public:''
    }
 });

This saves the file in the root of the bucket, inside folder "folderName".

Was this page helpful?
0 / 5 - 0 ratings