edit-icon download-icon

FAQ

Last Updated: Jan 23, 2018

How to enable HTTPS access

When you initialize the SDK, you can input the following parameters:

  • region: This parameter is the region used when you applied for the OSS service, such as oss-cn-hangzhou. Complete region list can be viewed in OSS Nodes.
  • internal: Use in combination with region. If internal is specified to true, visit the intranet node.
  • secure: Use in combination with region. If secure is specified to true, use the HTTPS for access.
  • endpoint: For example, http://oss-cn-hangzhou.aliyuncs.com. If the endpoint is specified, the region is ignored. You can specify HTTPS or IP when using endpoint.

How to obtain the upload progress

You can obtain the upload progress when using multipart upload. Related documents.

Note that the progress parameter can be a generator function(function*), or a “thunk”:

  1. var progress = function (p) {
  2. return function (done) {
  3. console.log(p);
  4. done();
  5. };
  6. };

How to obtain the download progress

The node can calculate the download progress based on the size of the download traffic.

How to upload Base64-encoded images

Convert the Base64 content to a File object and upload it to the OSS server on the call API.

  1. function dataURLtoFile(dataurl, filename) {
  2. var arr = dataurl.split(','), mime = arr[0].match(/:(.*?);/)[1],
  3. bstr = atob(arr[1]), n = bstr.length, u8arr = new Uint8Array(n);
  4. while(n--){
  5. u8arr[n] = bstr.charCodeAt(n);
  6. }
  7. return new File([u8arr], filename, {type:mime});
  8. }
  9. var file = dataURLtoFile('<base64 content>', '');
  10. client.multipartUpload('<oss file name>', file).then(function (res) {
  11. console.log(res)
  12. });

How to upload files to a specified directory

You only need to add the prefix of the specified directory to the name of the object to be uploaded, see: Comparison of OSS and file system.

  1. var co = require('co');
  2. var OSS = require('ali-oss')
  3. var client = new OSS({
  4. region: '<Your region>',
  5. accessKeyId: '<Your AccessKeyId>',
  6. accessKeySecret: '<Your AccessKeySecret>',
  7. bucket: 'Your bucket name'
  8. });
  9. co(function* () {
  10. var result = yield client.multipartUpload('base-dir/' +'object-key', 'local-file', {
  11. progress: function* (p) {
  12. console.log('Progress: ' + p);
  13. }
  14. });
  15. console.log(result);
  16. }).catch(function (err) {
  17. console.log(err);
  18. });

How to obtain the signed URL of an object

You can call the signatureUrl method to obtain the download address. See related documents.

Common errors

Thank you! We've received your feedback.