React native 是否有人在react本机项目中成功地将azure存储用于blob存储?
基于此项目或其他潜在项目,是否有人使用JavaScript包上传azure blob存储 我之所以在这里发帖,是因为我的研究没有得到什么结果,所以我认为,与azure缺乏react原生支持的潜在对话可能会发现一些解决方法 我将继续尝试列出的软件包,如果成功的话,我会提供结果,因此,我将一如既往地感谢您的回复和指导,我们将非常感谢 编辑: 这看起来很有趣,但我没有详细研究: 是的,我用过React native 是否有人在react本机项目中成功地将azure存储用于blob存储?,react-native,azure-storage,azure-blob-storage,React Native,Azure Storage,Azure Blob Storage,基于此项目或其他潜在项目,是否有人使用JavaScript包上传azure blob存储 我之所以在这里发帖,是因为我的研究没有得到什么结果,所以我认为,与azure缺乏react原生支持的潜在对话可能会发现一些解决方法 我将继续尝试列出的软件包,如果成功的话,我会提供结果,因此,我将一如既往地感谢您的回复和指导,我们将非常感谢 编辑: 这看起来很有趣,但我没有详细研究: 是的,我用过 const localUri = __IS_IOS ? file.uri.replace('file://'
const localUri = __IS_IOS ? file.uri.replace('file://', '') : file.uri;
const assetPath = `${_trimEnd(sasContainerUri, '/')}/${container}/${uploadPath}`;
await RNFetchBlob.fetch('PUT', `${assetPath}?${sasToken}`, {
'x-ms-blob-type': 'BlockBlob',
'content-type': 'application/octet-stream',
'x-ms-blob-content-type': file.type,
}, RNFetchBlob.wrap(localUri));
return assetPath
以防有人试图使用此处提出的其他解决方案。下面是另一个使用
rn fetch blob
的。此解决方案还允许使用自定义名称保存blob,例如,customBlobName
import RNFetchBlob from "rn-fetch-blob";
const sasContainerUri = "https://accountname.blob.core.windows.net";
const container = "minecontainer";
const sasToken =
"sv=2019-02-02&ss=b&srt=sco&sp=rwdlac&se=2020-05-30T22:48:22Z&st=2020-05-25T14:48:22Z&spr=https&sig=otherpartofSAStoken"; // you may need to play with other html verbs in this string e.g., `sp`, `ss` e.t.c.
const localUri = Constants.platform.ios
? file.uri.replace("file://", "/")
: file.uri;
const assetPath = `${sasContainerUri}/${container}/${customBlobName}`;
try {
await RNFetchBlob.fetch(
"PUT",
`${assetPath}?${sasToken}`,
{
"x-ms-blob-type": "BlockBlob",
"content-type": "application/octet-stream",
"x-ms-blob-content-type": file.type
},
RNFetchBlob.wrap(localUri)
);
} catch (e) {
console.log("Error at saving image into Azure Storage", e);
}
仅供澄清:您是否参考了以下链接中提到的建议:您可以使用Azure存储JavaScript客户端库直接将照片从客户端上载到Azure存储:。请参阅此处的示例:@SumanthMarigowda MSFT-除了您的第一个建议外,您所有的建议都是针对浏览器的。您对React Native mobile有什么帮助吗。谢谢你能演示一个更详细的解决方案吗?我收到“此请求未被授权执行此操作”。错误。我收到错误代码409。实体状态下不允许执行此操作。任何关于@Nikhil的解决方案,提前感谢我收到认证错误。有什么建议吗?服务器无法对请求进行身份验证。确保包含签名的授权标头的值格式正确。答案不完整,并给出错误“服务器无法验证请求。确保包含签名的授权标头的值格式正确。”
import RNFetchBlob from "rn-fetch-blob";
const sasContainerUri = "https://accountname.blob.core.windows.net";
const container = "minecontainer";
const sasToken =
"sv=2019-02-02&ss=b&srt=sco&sp=rwdlac&se=2020-05-30T22:48:22Z&st=2020-05-25T14:48:22Z&spr=https&sig=otherpartofSAStoken"; // you may need to play with other html verbs in this string e.g., `sp`, `ss` e.t.c.
const localUri = Constants.platform.ios
? file.uri.replace("file://", "/")
: file.uri;
const assetPath = `${sasContainerUri}/${container}/${customBlobName}`;
try {
await RNFetchBlob.fetch(
"PUT",
`${assetPath}?${sasToken}`,
{
"x-ms-blob-type": "BlockBlob",
"content-type": "application/octet-stream",
"x-ms-blob-content-type": file.type
},
RNFetchBlob.wrap(localUri)
);
} catch (e) {
console.log("Error at saving image into Azure Storage", e);
}