I am reading an image from a url and processing it. I need to upload this data to a file in cloud storage, currently i am writing the data to a file and uploading this file
The data can be uploaded without writing to a file by using nodes streams.
const stream = require('stream'),
dataStream = new stream.PassThrough(),
gcFile = cloudStorage.bucket(bucketName).file(fileName)
dataStream.push('content-to-upload')
dataStream.push(null)
await new Promise((resolve, reject) => {
dataStream.pipe(gcFile.createWriteStream({
resumable : false,
validation : false,
metadata : {'Cache-Control': 'public, max-age=31536000'}
}))
.on('error', (error : Error) => {
reject(error)
})
.on('finish', () => {
resolve(true)
})
})