All Products
Search
Document Center

Object Storage Service:FAQ

Last Updated:Oct 24, 2023

This topic provides answers to some frequently asked questions when you use OSS SDK for Node.js.

What do I do if the "The region must be conform to the specifications" error message is returned?

This error occurs because the Region parameter is invalid. Check whether the value of the Region parameter is valid. For more information about region IDs, see Regions and endpoints.

How do I enable HTTPS access?

To enable HTTPS access, set secure to true when you initialize OSS SDK for Node.js.

How do I obtain the upload progress?

When you perform multipart upload, you can obtain the upload progress by specifying the progress parameter.

How do I obtain the download progress?

You can calculate the progress in OSS SDK for Node.js based on the size of the download traffic.

How do I upload Base64-encoded images?

Convert the images to File objects and upload them to the OSS server by calling the corresponding API operation.

 function dataURLtoFile(dataurl, filename) {
    let arr = dataurl.split(','), mime = arr[0].match(/:(.*?);/)[1],
      bstr = atob(arr[1]), n = bstr.length, u8arr = new Uint8Array(n);
    while(n--){
      u8arr[n] = bstr.charCodeAt(n);
    }
    return new File([u8arr], filename, {type:mime});
  }

  let file = dataURLtoFile('base64 content', '');

  client.multipartUpload('oss file name', file).then( (res)=> {
    console.log(res)
  }).catch((err) => {
    console.log(err)
  });
            

How do I upload an object to a specified directory?

You only need to add the prefix of the directory to the name of the object that you want to upload. For more information, see Comparison between OSS and file systems.

const OSS = require('ali-oss')
const client = new OSS({
  // Specify the region in which the bucket is located. For example, if the bucket is located in the China (Hangzhou) region, set the region to oss-cn-hangzhou. 
  region: 'yourregion',
  // Obtain access credentials from environment variables. Before you run the sample code, make sure that you have configured environment variables OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET. 
  accessKeyId: process.env.OSS_ACCESS_KEY_ID,
  accessKeySecret: process.env.OSS_ACCESS_KEY_SECRET,
  // Specify the name of the bucket. 
  bucket: 'yourbucketname'
});

client.multipartUpload('base-dir/' +'object-name', 'local-file', {
    progress: async function (p) {
      console.log('Progress: ' + p);
    }
  });
  console.log(result);
}).then((res) => {
  console.log(res)
}). catch((err) => {
  console.log(err);
});            

How do I generate a signed URL to upload an object?

If you use the PUT method to upload an object, you must generate a signed URL. For more information, see Use a signed URL for temporary access authorization.

Signed URLs are not supported for object upload by using the POST method. You can construct a POST request to upload objects. When you construct a POST request, you must configure the Key, OSSAccessKeyId, policy, and Signature parameters in the order specified in the API operation. For more information about the operation, see PostObject.

How do I obtain the signed URL of an object?

You can call the signatureUrl method to obtain the signed URL used to download an object. For more information, visit GitHub.

What do I do if the error message "Response timeout for 60000ms, please increase the timeout or use multipartDownload" is reported when I download an object that exceeds 1 GB in size?

The timeout period for OSS SDK for Node.js to perform download tasks is 60000 ms. If a timeout error occurs when you download an object greater than 1 GB, perform streaming download to download the object in increments and appropriately extend the timeout period. For more information about streaming download, see Streaming download. For more information about the timeout parameter, see Parameters.