我正在使用React-native和Node.js为服务器开发一个应用程序,它已经花时间来实现个人资料图片。我当时正在考虑使用Microsoft Azure存储,特别是Blob存储服务来保存文件。我知道如何使用Blob Storage服务,所以我想将图像发送到服务器,然后从服务器发送到Azure。但是,当我可以从react-native应用程序发送图像时,我认为我正在使用额外的步骤。
任何人都知道是否可以在本地做反应?我该如何实施呢? 或者也许有一种简单的方法可以推荐我的个人资料图片。
提前致谢!
答案 0 :(得分:1)
您可以使用Azure存储JavaScript客户端库直接将照片从客户端上传到Azure存储:https://github.com/Azure/azure-storage-node/tree/master/browser
请参阅此处的示例:https://github.com/Azure/azure-storage-node/blob/master/browser/samples/sample-blob.html
答案 1 :(得分:0)
您可以使用 rn-fetch-blob
将文件/图像上传到 azure blob 存储示例代码
const storageURL = 'account_name.blob.core.windows.net';
const assetPath = `${storageURL}/${container_name}/${file_name}.png`;
const file = this.state.selectedImage;
await RNFetchBlob.fetch(
"PUT",
`${assetPath}?${sas.token}`,
{
"x-ms-blob-type": "BlockBlob",
"content-type": "application/octet-stream",
"x-ms-blob-content-type": file.type
},
RNFetchBlob.wrap(file.uri)
)
.progress((progress) => {
console.log("Progress ==> ", progress);
})
.uploadProgress((progress) => {
console.log("Upload Progress ==> ", progress);
})
.then((response) => {
console.log("Success Response ==> ", JSON.stringify(response));
})
.catch((e) => {
console.log("Error at saving image into Azure Storage", JSON.stringify(e));
})