node.jsazure-blob-storagecontent-dispositionazure-node-sdk

NodeJS '@azure/storage-blob': How do set Blob Service Properties when uploading a file


From this document, there is no example to set Blob Service Properties.

Below is my Sample Code:

let containerClient = blobServiceClient.getContainerClient(CONTAINERNAME),
    blockBlobClient = containerClient.getBlockBlobClient(BLOBNAME);

await blockBlobClient.uploadFile(FILEPATH);

Please advise how I can upload a file with setting contentDisposition and contentType in properties of blockBlob.


Solution

  • Please try this way:

        const blobOptions = { blobHTTPHeaders: { blobContentType: 'image/jpeg', blobContentDisposition: "attachment; filename=package.jpg" } };
        const uploadBlobResponse =await blockBlobClient.uploadFile(filePath,blobOptions);
    

    If there are other questions, please let me know!