Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set contenttype on azure blob storage with nodejs

I've got a nodejs server, am using the azure-storage module and am trying to upload a wav file to azure blob storage.

I'm trying to set the contentType on the blob to 'audio/wav' but it is showing up in storage as 'application/octet-stream'. Code is:

 upload: function (id, buffer, mimeType, callback) {
    self = this;
    var size = buffer.length;
    var stream = streamifier.createReadStream(buffer);
    var options = { contentType: 'audio/wav' };
    self.blobService.createBlockBlobFromStream(self.containerName, id, stream, size, options,  function (error, result, response) {
        if (error) {
            callback(error);
        }
        callback(null);
    });
}

Any ideas as to what I'm doing wrong?

like image 746
klb Avatar asked Jul 09 '16 15:07

klb


People also ask

How do you acquire an exclusive lock on a blob?

To lock a blob for exclusive use, you can acquire a lease on it. When you acquire the lease, you specify the duration of the lease. A finite lease may be valid from between 15 to 60 seconds. A lease can also be infinite, which amounts to an exclusive lock.

How do you upload images to Azure Blob Storage?

Sign in to the Azure portal. From the left menu, select Storage accounts, then select the name of your storage account. Select Containers, then select the thumbnails container. Select Upload to open the Upload blob pane.


2 Answers

It has changed again, according the source code, the upload can expect a BlockBlobUploadOptions, with an optional blobHTTPHeaders object. This gives you the possibility to set http headers to set for the blob when requested. Too bad, none of the sample goes into that much details what to set when uploading blobs.

This worked for me

const blobOptions = { blobHTTPHeaders: { blobContentType: 'text/plain' } };
const uploadBlobResponse = await blockBlobClient.upload(ascii, ascii.length, blobOptions);
like image 119
BigDaddy Avatar answered Sep 21 '22 01:09

BigDaddy


According the comments in source code at Github, the option architecture has changed, to define the contentType, please try to use following code snippet:

var options = {contentSettings:{contentType:'audio/wav'}}

Any further concern, please feel free to let me know.

like image 25
Gary Liu Avatar answered Sep 21 '22 01:09

Gary Liu