“NodeJS S3 Baca” Kode Jawaban

NodeJS S3 Baca

# This function for read/download file from s3 bucket
const s3download = function (params) {
    return new Promise((resolve, reject) => {
        s3.createBucket({
            Bucket: BUCKET_NAME        /* Put your bucket name */
        }, function () {
            s3.getObject(params, function (err, data) {
                if (err) {
                    reject(err);
                } else {
                    console.log("Successfully dowloaded data from  bucket");
                    resolve(data);
                }
            });
        });
    });
}
Cooperative Cormorant

NodeJS S3 Baca

const params = {
  Bucket: BUCKET_NAME,  /* required */        # Put your bucket name
  Key: fileName         /* required */        # Put your file name
};
Cooperative Cormorant

NodeJS S3 Baca

const s3 = new AWS.S3({
  accessKeyId: IAM_USER_KEY,  /* required */ # Put your iam user key
  secretAccessKey: IAM_USER_SECRET, /* required */  # Put your iam user secret key
  Bucket: BUCKET_NAME     /* required */     # Put your bucket name
});
Cooperative Cormorant

NodeJS S3 Baca

# This function for delete file from s3 bucket
const s3delete = function (params) {
    return new Promise((resolve, reject) => {
        s3.createBucket({
            Bucket: BUCKET_NAME        /* Put your bucket name */
        }, function () {
            s3.deleteObject(params, function (err, data) {
                if (err) console.log(err);
                else
                    console.log(
                        "Successfully deleted file from bucket";
                    );
                console.log(data);
            });
        });
    });
};
Cooperative Cormorant

NodeJS S3 Baca

#This function for upload file to s3 bucket
const s3upload = function (params) {
    return new Promise((resolve, reject) => {
        s3.createBucket({
            Bucket: BUCKET_NAME        /* Put your bucket name */
        }, function () {
            s3.putObject(params, function (err, data) {
                if (err) {
                    reject(err)
                } else {
                     console.log("Successfully uploaded data to bucket");
                    resolve(data);
                }
            });
        });
    });
}
Cooperative Cormorant

NodeJS S3 Baca

$ npm install aws-sdk
Cooperative Cormorant

Jawaban yang mirip dengan “NodeJS S3 Baca”

Pertanyaan yang mirip dengan “NodeJS S3 Baca”

Lebih banyak jawaban terkait untuk “NodeJS S3 Baca” di JavaScript

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya