s3-nodejs-sample
Author: Chandrakant Thakkar
Created on: 13th January,2017
This is a node module illustrating usage of the AWS SDK for Node.js.To use this just dowload this module,create config.js file to set credentials and use below functions.
Requirements
The only requirement of this application is the Node Package Manager. All other dependencies (including the AWS SDK for Node.js) can be installed with:
npm install
Basic Configuration
You need to set up your AWS security credentials before the sample code is able to connect to AWS. You can do this by creating setting accessKeyId,secretAccessKey,proxy parameters in config.js file. Open config.js file and set the parameters:
credentials={
"accessKeyId" : "****",
"secretAccessKey" :"****",
"proxy":"****"
}
module.exports={
credentials:credentials
}
See the Security Credentials page. It's also possible to configure your credentials via a configuration file or directly in source. See the AWS SDK for Node.js Developer Guide for more information.
"accessKeyId" and "secretAccessKey" are provided when you create an aws account.
Proxy is required if you are using your company's internet else set "localhost" in proxy.
Running the S3 sample
node sampleFile.js
List of Functions
- createBucket()
- createFile()
- uploadFile()
- getUploadedFile()
- getFileData()
- listAllBucket()
- listAllFiles()
- removeFile()
- removeBucket()
- getBucketPermission()
- isBucketExist()
- getObject()
1. createBucket()
- Example
var s3BucketMgt=;var config=;var bucketName="node-sdk-sample-cbt-003";s3BucketMgt;
2. createFile()
- Example
s3BucketMgt=;var config=;var bucketName="node-sdk-sample-cbt-003";var fileName="sampleFile.txt";var fileContents="This is demo created by Chandrakant Thakkar.";s3BucketMgt;
3. uploadFile()
- Example
s3BucketMgt=;var config=;var bucketName="node-sdk-sample-cbt-003";var fileToUpload = "D:/gitHub/awt-nodejs-sample/s3-nodejs-sample/logo.jpg";s3BucketMgt; or//CBT:create file with specific namevar fileToCreate="sample.jpg"s3BucketMgt;
4. getUploadedFile()
- Example
s3BucketMgt=;var config=;var bucketName="node-sdk-sample-cbt-003";s3BucketMgt;
5. getFileData()
- Example
s3BucketMgt=;var config=;var bucketName="node-sdk-sample-cbt-003";var fileName="sampleFile.txt";s3BucketMgt;
6. listAllBucket()
- Example
s3BucketMgt=;var config=;s3BucketMgt;
7. listAllFiles()
- Example
s3BucketMgt=;var config=;var bucketName="node-sdk-sample-cbt-003";s3BucketMgt;
8. removeFile()
- Example
s3BucketMgt=;var config=;var bucketName="node-sdk-sample-cbt-003";var fileName="sampleFile.txt";s3BucketMgt;
9. removeBucket()
- Example
s3BucketMgt=;var config=;var bucketName="node-sdk-sample-cbt-003";s3BucketMgt;
10. getBucketPermission()
- Example
s3BucketMgt=;var config=;var bucketName="node-sdk-sample-cbt-003";s3BucketMgt;
11. isBucketExist()
- Example
s3BucketMgt=;var config=;var bucketName="node-sdk-sample-cbt-003";s3BucketMgt;
12. getObject()
- Example
//CBT:It will return binary format of datas3BucketMgt=;var config=;var bucketName="node-sdk-sample-cbt-003";var fileName="logo.jpg";s3BucketMgt;