简体   繁体   中英

Upload file to Azure blob fails from Electron app

I'm building an electron app with Vue.js. I would like my users to download and upload files, these files are kept in an Azure Blob.

I've successfully managed to make the downloads work, but I have an issue with the uploads. I'm using the following code in my Vue component:


import { BlobServiceClient } from '@azure/storage-blob'

const blobServiceClient = BlobServiceClient.fromConnectionString('connString')
const containerClient = blobServiceClient.getContainerClient('my container name')
const blockBlobClient = await this.containerClient.getBlockBlobClient('name of my blob')
const uploadBlobResponse = await blockBlobClient.uploadFile('C://dev//animage.jpg')

The error I get is 'TypeError: Cannot read property 'size' of undefined', which originates in the uploadFile method:

在此处输入图像描述

It seems that fsStat is not able to parse the filePath I'm giving.

I've tried with different paths, also with path.parse() but without any luck. Does anyone know what I'm doing wrong here?

  • The reason you are getting undefined as an answer because the fs.stats is an async function and without passing a callback function it will give answer as undefined .

  • Now I will suggest you use fs.fstatSync function this is a synchronous function and will return all the stats of the file.

const  fs = require('fs');
const  file_fd = fs.openSync('./test.txt', 'r');let  r = fs.fstatSync();
console.log("Size of File : ",r.size);
  • Here the r represents all the stats of the file and you can access the size of the file as r.size

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM