I am using the following code to upload the image on amazon S3, but it is not public. What else parameter do I need to pass to make it public.
var AWS = require('aws-sdk');
AWS.config.region = 'us-west-2';
var s3bucket = new AWS.S3({params: {Bucket: 'myBucket'}});
s3bucket.createBucket(function() {
var params = {Key: 'myKey', Body: 'Hello!'};
s3bucket.upload(params, function(err, data) {
if (err) {
console.log("Error uploading data: ", err);
} else {
console.log("Successfully uploaded data to myBucket/myKey");
}
});
});
Before you can upload files to an Amazon S3 bucket, you need write permissions for the bucket. For more information about access permissions, see Identity and access management in Amazon S3. You can upload any file type—images, backups, data, movies, etc.
Make resource public when upload data at s3 bucket. I can able to download that link from any where.
Just try it:
var s3bucket = new AWS.S3({
region: Constant.AWS_S3_REGION
});
console.log(filename);
var params = {
Key: filename,
Body: fs.createReadStream(filepath),
Bucket: Constant.AWS_S3_BUCKET,
ACL:'public-read-write'
};
s3bucket.upload(params, cb)
Cheers...!!!!
For making data public in your bucket, convert following :
var params = {Key: 'myKey', Body: 'Hello!'};
To following:
var params = {Key: 'myKey', Body: 'Hello!', ACL: 'public-read'};
For better understanding follow This Good Tutorial
Happy Helping!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With