-
Notifications
You must be signed in to change notification settings - Fork 55
Support putting a publicly readable file to S3 bucket #166
base: develop
Are you sure you want to change the base?
Conversation
Add an optional boolean parameter named `makePublic` to the `put()` method. If `makePublic` is public, sets `ACL: 'public-read'` on the params, otherwise sets it to 'private', which is the default behavior. This change is backward compatible.
Need this PR to be merged 🥲 |
Is anyone merging this PR soon? |
I made fork of this package @kodepandai/flydrive. You can use it with @kodepandai/flydrive-s3 driver. storage.put(path, content, {
ContentType: 'image/jpg',
ACL: 'public-read', //this for make file public
CacheControl: ....,
...etc
}) But, my package only works on Esmodule. I made it for my internal project |
I'd personally prefer having this third option object with various options rather than making the 3rd parameter a boolean only for the purpose of making the file public. Thanks for the fork @axmad386 - do you plan to do a PR to have this merged in the original project? |
@jthomaschewski I am not sure. I think my fork will break the original one. It's because I am focusing in esm mode. Except I must refactor my code maybe using rollup to support both esm and cjs. But I don't have much time for now. Sorry |
Any update on this? |
You can create a custom class that extends this class and override the export class YourAWSStorage extends AmazonWebServicesS3Storage {
/**
* Creates a new file.
* This method will create missing directories on the fly.
*/
public async put(location: string, content: Buffer | NodeJS.ReadableStream | string, makePublic: boolean = false): Promise<Response> {
const params = { Key: location, Body: content, Bucket: this.$bucket, ACL: makePublic ? 'public-read' : 'private' };
try {
const result = await this.$driver.upload(params).promise();
return { raw: result };
} catch (e) {
throw handleError(e, location, this.$bucket);
}
}
} |
Great idea!! @njsubedi, how did I not think about that haha? Thank you! |
Add an optional boolean parameter named
makePublic
to theput()
method. IfmakePublic
is public, setsACL: 'public-read'
on the params, otherwise sets it to 'private', which is the default behavior. This change is backward compatible.This PR does not break anything.