我想更新天蓝色blob存储上的图像。我下载了@azure/storage-blob
和@azure/identity
,即使在所有这些下载之后我都遇到了错误,并且在下载@azure/logger
之后,它显示了错误
“退出节点1”
代码如下。
var AzureStorage = require('azure-storage');
const account = { name: "x", sas:"x" };
var blobUri = 'https://' + account.name + '.blob.core.windows.net';
var blobService = AzureStorage.Blob.createBlobServiceWithSas(blobUri, account.sas);
console.log(azureinformation);
console.log(AzureStorage);
blobService.createBlockBlobFromBrowserFile('aic', "task1", data.sampleImgData, function(error, result, response) {
finishedOrError = true;
if (error) {
console.log(success);
}
});
我正在使用.61版本的react native。如果有的话,请让我知道解决方案。预先感谢。
答案 0 :(得分:0)
您的描述和代码中有一些错误,如下所示。
最新版本为@azure/storage-blob
(其版本> = 10),但不包括属于V2 SDK的函数createBlockBlobFromBrowserFile
。您可以参考类似的SO线程Upload BlockBlob to Azure Storage using React。
您当前的代码似乎来自示例Azure Storage JavaScript Client Library Sample for Blob Operations
,但是您应该通过HTML页面中的代码AzureStorage
而不是<script src="azure-storage.blob.js"></script>
获得变量var AzureStorage = require('azure-storage');
用于节点服务器。
如果要在浏览器中使用最新的SDK @azure/storage-blob
,请参见示例代码https://github.com/Azure/azure-sdk-for-js/blob/master/sdk/storage/storage-blob/samples/browserSamples/largeFileUploads.js。
因此,首先,您应该选择一个SDK版本作为当前需求的解决方案。
答案 1 :(得分:0)
我已使用所列出的代码将图像上传到了蔚蓝斑点上。我使用图像选择器获取图像,然后
{
let blobUri = `https://containername.blob.core.windows.net`;
let sas = "genrate sas token from storage account and give expire limit of 1 year";
let resposne = RNFetchBlob.fetch('PUT', `${blobUri}/aic/${data.sampleImgData.uri.fileName}?${sas}`, {
'x-ms-blob-type': 'BlockBlob',
'content-type': 'application/octet-stream',
'x-ms-blob-content-type': data.sampleImgData.uri.type,
}, data.sampleImgData.uri.data);
resposne.then(res => console.log(res)).catch(err => console.log(err));
console.log(`${blobUri}/aic/${data.sampleImgData.uri.fileName}`);
azureimageurl = `${blobUri}/aic/${data.sampleImgData.uri.fileName}`;
}