Попробуйте это с помощью axios:
var axios = require('axios').default;
var fs = require('fs');
var crypto = require('crypto');
var storageKey = "<your storage key>"
var accountName = "<your storage account name>"
var containerName="<your container name>"
var fileName="<file name>"
var filePath = "<file path ,including file name>"
var fileLength= fs.statSync(filePath).size
var fileStream = fs.createReadStream(filePath);
var blobType ="BlockBlob"
var date = new Date().toUTCString()
var blobServiceVersion = "2014-02-14"
var storageBlobEndpoint = "https://"+ accountName +".blob.core.windows.net"
var requestURL = storageBlobEndpoint + "/" + containerName + "/" + fileName
var requestMethod = "PUT"
var canonicalizedHeaders = "x-ms-blob-type:"+ blobType +"\nx-ms-date:"+ date +"\nx-ms-version:" + blobServiceVersion;
console.log("headers :"+canonicalizedHeaders);
var canonicalizedResource = accountName + "/" + containerName + "/" + fileName
var stringToSign = requestMethod+"\n\n\n"+fileLength+"\n\napplication/x-www-form-urlencoded\n\n\n\n\n\n\n" + canonicalizedHeaders + "\n/" + canonicalizedResource
var signature = crypto.createHmac('sha256', Buffer.from(storageKey, 'base64')).update(stringToSign, 'utf-8').digest('base64');
var authorizationHeader = "SharedKey "+accountName + ":" + signature
const result = axios({
baseURL: requestURL,
method: requestMethod,
data:fileStream,
headers: {
'Content-Length':fileLength,
'x-ms-blob-type': blobType,
'x-ms-date':date,
'x-ms-version':blobServiceVersion,
'Authorization' : authorizationHeader
}
}).then(function (response) {
console.log(response);
})
.catch(function (error) {
console.log(error);
})
.finally(function () {
//add finally function here if needed
});
Использование остальных API-интерфейсов для загрузки файлов в хранилище довольно сложно. Использование SDK будет намного проще. Надеюсь, это поможет.