Reactjs 使用React将映像上载到Azure Blob存储
我想使用React将图像上载到Azure Blob存储 我试过很多例子,但都不管用 看起来最好的一个是,但仍然没有设法让它在React上工作 我现在尝试的是使用createContainerIfNotExists方法只是为了测试,错误是Reactjs 使用React将映像上载到Azure Blob存储,reactjs,azure-blob-storage,Reactjs,Azure Blob Storage,我想使用React将图像上载到Azure Blob存储 我试过很多例子,但都不管用 看起来最好的一个是,但仍然没有设法让它在React上工作 我现在尝试的是使用createContainerIfNotExists方法只是为了测试,错误是无法读取属性createBlobservicewithas of undefined 我的代码如下: import AzureStorage from 'azure-storage'; const account = { name: 'x', sas:
无法读取属性createBlobservicewithas of undefined
我的代码如下:
import AzureStorage from 'azure-storage';
const account = {
name: 'x',
sas: 'x',
};
const blobUri = `https://${account.name}.blob.core.windows.net`;
const blobService = AzureStorage.Blob.createBlobServiceWithSas(blobUri, account.sas);
export const createContainer = () => {
blobService.createContainerIfNotExists('test', (error, container) => {
if (error) {
// Handle create container error
} else {
console.log(container.name);
}
});
};
export default createContainer;
根据我的研究,因为您开发了React应用程序,所以我们不能使用
createBlockBlobFromBrowserFile
方法。我们可以在浏览器中使用该方法。有关更多详细信息,请参阅。
根据这种情况,我建议您使用另一种方法(例如
uploadStreamToBlockBlob
)使用V10SDK上传图像。有关更多详细信息,请参阅能否告诉我您的错误消息?此外,能否提供您的测试代码?@JimXu编辑了这篇文章以显示我的实际代码您是否在html页面中添加了
?根据我的研究,仅支持使用经典的单一JS捆绑文件的浏览器使用。因此,您需要参考js文件。如果您仍然使用sdk,我建议您使用Azure storage sdk v10。有关更多详细信息,请参阅和。