1

i try upload a pdf to Google cloud Storage but i dont know why the file size is 0 bytes...

already i have try resolve this during 3 days but i not have response.. this is my code:

const  cv = request.file('cv')
  
      console.log(cv)
    
        const gc = await new Storage({
          projectId: GOOGLE_CLOUD_PROJECT_ID,
          keyFilename: GOOGLE_CLOUD_KEYFILE,
        })

        const bucked = gc.bucket('rootbusco')
        const file = bucked.file(cv.stream.filename)

         const stream = await cv.stream.pipe(file.createWriteStream({
          resumable: false,
          gzip: true,
          metadata: {
            contentType: cv.stream.headers['content-type']
          }
        }))

        stream.end(cv.stream.data);

thanks for the asks

Ralemos
  • 5,571
  • 2
  • 9
  • 18
Gario3
  • 139
  • 2
  • 13

1 Answers1

1

You are creating the stream from the your request file object(cv.stream.pipe), that is incorrect, you will only use that in the stream.end() to actually fill in the data, so if change this piece of your code to the following (untested) code, it should work:

const stream = file.createWriteStream({
    resumable: false,
    gzip: true,
    metadata: {
        contentType: cv.stream.headers['content-type']
    }
})
Ralemos
  • 5,571
  • 2
  • 9
  • 18