flydrive icon indicating copy to clipboard operation
flydrive copied to clipboard

Support putting a publicly readable file to S3 bucket

Open njsubedi opened this issue 4 years ago • 8 comments

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.

This PR does not break anything.

njsubedi avatar Jul 20 '21 12:07 njsubedi

Need this PR to be merged :smiling_face_with_tear:

axmad386 avatar Jan 24 '22 08:01 axmad386

Is anyone merging this PR soon?

wilforlan avatar Jan 27 '22 16:01 wilforlan

Is anyone merging this PR soon?

I made fork of this package @kodepandai/flydrive. You can use it with @kodepandai/flydrive-s3 driver. In put method, there are additional s3 PutObjectRequest on 3rd params

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

axmad386 avatar Jan 30 '22 11:01 axmad386

storage.put(path, content, {
   ContentType: 'image/jpg',
   ACL: 'public-read', //this for make file public
   CacheControl: ....,
   ...etc
})

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 avatar Mar 18 '22 15:03 jthomaschewski

storage.put(path, content, {
   ContentType: 'image/jpg',
   ACL: 'public-read', //this for make file public
   CacheControl: ....,
   ...etc
})

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

axmad386 avatar Mar 19 '22 02:03 axmad386

Any update on this? I'm uploading profile pictures on gcs and I need the pictures to be public If not merged, what's a workaround to make a file public?

sagarPakhrin avatar Jul 06 '22 09:07 sagarPakhrin

You can create a custom class that extends this class and override the put function.


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);
		}
	}

}

njsubedi avatar Jul 06 '22 11:07 njsubedi

Great idea!! @njsubedi, how did I not think about that haha? Thank you!

wilforlan avatar Jul 07 '22 14:07 wilforlan