[英]Upload a image to Microsoft Azure Blob Storage with node js
I am trying to upload a image to my blob storage but it upload text of the file path instead of image我正在尝试将图像上传到我的 blob 存储,但它上传的是文件路径的文本而不是图像
const { BlobServiceClient, StorageSharedKeyCredential } = require("@azure/storage-blob");
const account = "<account name hided";
const accountKey = "<key hided>";
const sharedKeyCredential = new StorageSharedKeyCredential(account, accountKey);
const blobServiceClient = new BlobServiceClient(
`https://${account}.blob.core.windows.net`,
sharedKeyCredential
);
var containerName = 'democontainer1';
async function createContainer() {
const containerClient = blobServiceClient.getContainerClient(containerName);
var blobName = "newblob" + new Date().getTime();
var filePath = "./newblob.jpg";
const blockBlobClient = containerClient.getBlockBlobClient(blobName);
const uploadBlobResponse = await blockBlobClient.upload(filePath, filePath.length);
console.log(`Upload block blob ${blobName} successfully`, uploadBlobResponse.requestId);
}
createContainer();
Please change the following line of code:请更改以下代码行:
const uploadBlobResponse = await blockBlobClient.upload(filePath, filePath.length);
to至
const uploadBlobResponse = await blockBlobClient.uploadFile(filePath);
and you should see proper blob being uploaded.并且您应该看到正确的 blob 正在上传。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.