0
votes

I am searching for a solution to stream 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

1

1 Answers

0
votes

Use createBlockBlobFromLocalFile directly:

blobService.createBlockBlobFromLocalFile(containerName, fileName, sourceFilePath, (err) => {
    // Handle err
});