This document is based on AWS Node.js SDK. JD Cloud Object Storage Service is compatible to AWS S3 interface. For the details of compatible interface, please view Compatible Interface.
You need to install the environment dependence before development: npm Address.
The preferred method for installing SDK for Node.js is to use the Node.js program package manager npm. To execute this operation, please enter the content in the command line.
npm install aws-sdk
If you get an error message as below during the installation:
npm WARN deprecated node-uuid@1.4.8: Use uuid module instead
npm uninstall --save node-uuid npm install --save uuid
The use of SDK requires your running environment to include nodejs and npm. We recommend that the nodejs adopts 7.0 version and above. After installation of npm, you also need to install npm dependent package and execute npm install in the SDK decompression directory. Go to Console AccessKey Management to obtain your items of AccessKeyId and AccessKeySecret.
Description:
For the meaning of the names shown in this document, such as AccessKeyId, AccessKeySecret and Bucket, please refer to OSS-Core Concepts.
JD Cloud OSS is compatible to most of AWS S3 APIs.
When using a development tool package in Node.js, you can use require
to add the development tool package to the application program.
var AWS = require('aws-sdk');
If you only use JD Cloud OSS, we suggest that you should use a method of only introducing Object Storage Service, from this, the code quantity transmitted via network and the memory overhead of codes will be significantly reduced.
The Object Storage Service only including the development tool package is shown as below.
// Import the AWS SDK
var AWS = require('aws-sdk');
var s3 = new AWS.S3({apiVersion: '2006-03-01'});
s3.endpoint = "https://s3.cn-north-1.jdcloud-oss.com"
s3.config.update({
accessKeyId: "your_accessKeyId",
secretAccessKey: "your_secretAccessKey",
s3ForcePathStyle: true,
signatureVersion: "v4"
})
Description You must subscribe JD Cloud Object Storage Service in OSS Console before using SDK to create Bucket. For the subscription process, please refer to Getting Started-Subscribe Object Storage Service. You can also create Bucket via the Console. Refer to Getting Started-Create Bucket.
// Create Client
var AWS = require('aws-sdk');
// Import the AWS SDK only for S3
var s3 = new AWS.S3({apiVersion: '2006-03-01'});
s3.endpoint = "https://s3.cn-north-1.jdcloud-oss.com"
s3.config.update({
accessKeyId: "XXXXXXXXXXXXXXXXXXXXXXXXXX",
secretAccessKey: "yyyyyyyyyyyyyyyyyyyyyyyyyyy",
signatureVersion: "v4"
})
// Create Bucket
var newBuket = {
Bucket: 'myAPPname'
}
s3.createBucket(newBuket, function (err, data) {
if (err) console.log(err, err.stack) // an error occurred
else {
console.log(data)
}
}
)
For more examples, please refer to Class in API Reference.
我们的产品专家为您找到最合适的产品/解决⽅案
1v1线上咨询获取售前专业咨询
专业产品顾问,随时随地沟通