Reputation: 69
I am trying to upload a image to my blob storage but it upload text of the file path instead of image
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();
Upvotes: 3
Views: 3250
Reputation: 136136
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.
Upvotes: 3