How to use AWS SDK for JavaScript with Stook?
Integrate Medianova Stook Object Storage into your JavaScript applications using the AWS SDK.
You can use the AWS SDK for JavaScript to connect your applications to Medianova Stook Object Storage. With the SDK, you can set credentials, create buckets, and upload files directly to Stook.
Prerequisites
Node.js installed on your system
AWS SDK for JavaScript installed
Medianova Stook credentials:
Access Key
Secret Key
Endpoint
Installation
Install the AWS SDK for JavaScript:
npm install aws-sdk
Example: Create Bucket and Upload File
sample.js
var AWS = require('aws-sdk');
var config = { s3ForcePathStyle: true };
var credentials = new AWS.SharedIniFileCredentials({profile: 'medianova'});
AWS.config.credentials = credentials;
AWS.config.update(config);
var ep = new AWS.Endpoint('*******.mncdn.com');
var s3 = new AWS.S3({endpoint: ep});
var bucketName = 'medianovatest';
var keyName = 'hello_world.txt';
s3.createBucket({Bucket: bucketName}, function() {
var params = {Bucket: bucketName, Key: keyName, Body: 'Hello World!'};
s3.putObject(params, function(err, data) {
if (err) console.log(err);
else console.log("Successfully uploaded data to " + bucketName + "/" + keyName);
});
});
Config.json Example
You can configure credentials in config.json
or under ~/.aws/credentials
.
config.json
:
{
"accessKeyId": "your_medianova_access_key",
"secretAccessKey": "your_medianova_secret_key",
"region": "us-east-1"
}
Running the Script
If credentials are saved under ~/.aws/credentials
with profile medianova
:
AWS_PROFILE=medianova node sample.js
Expected output:
Successfully uploaded data to node-sdk-sample-xxxx/hello_world.txt
Troubleshooting / FAQ
Error: Credentials not found
Solution: Ensure
config.json
or~/.aws/credentials
contains valid keys.
Error: Bucket already exists
Solution: Use a unique bucket name.
Error: Connection issues
Solution: Verify endpoint URL and network connectivity.
References
Last updated
Was this helpful?