Node.js
Node.js
Demonstrate S3_UploadBytes
Demonstrates how to upload a file to the Amazon S3 service.Chilkat Node.js Downloads
NODEJS_PRELUDE
function chilkatExample() {
var success = false;
// This example assumes the Chilkat HTTP API to have been previously unlocked.
// See Global Unlock Sample for sample code.
var http = new chilkat.Http();
http.AwsAccessKey = "AWS_ACCESS_KEY";
http.AwsSecretKey = "AWS_SECRET_KEY";
var bucketName = "chilkat.qa";
var objectName = "images/sea_creatures/starfish.jpg";
var localFilePath = "qa_data/jpg/starfish.jpg";
var contentType = "image/jpg";
var jpgData = new chilkat.BinData();
success = jpgData.LoadFile(localFilePath);
if (!success) {
console.log("Failed to load " + localFilePath);
return;
}
jpgBytes = jpgData.GetBinary();
success = http.S3_UploadBytes(jpgBytes,contentType,bucketName,objectName);
if (success !== true) {
console.log(http.LastErrorText);
return;
}
console.log("Success. File uploaded.");
}
chilkatExample();