locked
upload a zip file to blob-storage RRS feed

  • Question

  • I am searching for a solution to upload my zip file in order to send it through to azure blob-storage. Currently this is what I have

    async _uploadStreamToBlob(zipFile, fileName) {
        const blobService = await this.__self.blobStorage.createBlobService(this.__self.blobStorageConnectionString);
        const containerName = this.__self.blobContainerName;
    
        const sourceFilePath = `${path.resolve(zipFile)}`;
        const streamSource = fs.createReadStream(sourceFilePath);
        return new Promise((resolve, reject) => {
            streamSource.pipe(blobService.createWriteStreamToBlockBlob(containerName, fileName, error => {
                if (error) {
                    reject(error);
                } else {
                    resolve({ message: `Upload of '${fileName}' complete` });
                }
            }));
        });
    };

    This clearly does not work as I've tested otherwise since the fileStream feeds zero bytes into the pipe, resulting in a succesful upload of a 0 byte zipFile into the blob-storage. How do I stream the zipFile onto the azureWriteStream? Or how do I get the bytes off of the zipFile(preserving the contents)? If there is any other way to achieving this, I am all ears. Thanks

    ps: tried createBlockBlobFromLocalFile initially but same issue so tried streaming it in, but no dice.

    Tuesday, September 11, 2018 1:55 PM

All replies

  • You can try to upload using this

    Tuesday, September 11, 2018 2:14 PM
  • thanks for the reply, it is a node.js project and I followed instructions at https://docs.microsoft.com/en-us/azure/storage/blobs/storage-quickstart-blobs-nodejs. Upload of a normal text file or even xlsx works but no luck for .zip files.
    • Edited by afqd Tuesday, September 11, 2018 2:24 PM
    Tuesday, September 11, 2018 2:24 PM
  • This feature is under review. You can add your feedback here.

    --------------------------------------------------------------------------------------------------

    If this answer was helpful, click “Mark as Answer” or Up-Vote. To provide additional feedback on your forum experience, click here

    • Proposed as answer by Sandeep BR Wednesday, September 19, 2018 7:02 PM
    Wednesday, September 19, 2018 7:02 PM