1

I'm trying to download a image/file from an url which I receive from typeform but this is a direct download and not a picture you can actually view with the url.

I've succesfully made a buffer from it with bent:

const bent = require('bent');
const getBuffer = bent('buffer');
async function getBase64FromFileAsync(fileUrl) {
    let bentbuffer = await getBuffer(fileUrl); // returns hex string
    return bentbuffer.toString('base64');
    // ^ Base64 string
}

Where I was unsuccesful with js:

let fsbuffer = fs.readFileSync(fileUrl);
// ^ undefined

But with this I can't actually seem to do anything so that I can save the image to the firebase store.

I tried using the createReadSteam & createWriteStream with the actually url, base64 or even hex string

const remoteFile = bucket.file('image.png');
fs.createReadStream(fileUrl)
    .pipe(remoteFile.createWriteStream({

I tried the bucket.upload method also with the url, base64 and hex but upload requires an actual local file (which is not possible as it's a google cloud function (read-permissions only))

getBase64FromFileAsync(fileUrl)
    .then(base64 => {
        bucket.upload(base64, options, function (err, file) {

Is it possible to upload a file without downloading a local copy to "move" to the firebase storage or am I creating the file in a bad way?

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
Wanjia
  • 799
  • 5
  • 19
  • To upload data to Cloud Storage, you need to have that data locally. There is no way to upload data from a URL to Cloud Storage. The closest you can get is streaming, as shown here: https://stackoverflow.com/questions/18107545/can-i-upload-files-to-google-cloud-storage-from-url – Frank van Puffelen Feb 18 '20 at 16:00

0 Answers0