googleapis / nodejs-storage

Node.js client for Google Cloud Storage: unified object storage for developers and enterprises, from live data serving to data analytics/ML to data archiving.
https://cloud.google.com/storage/
Apache License 2.0
903 stars 370 forks source link

Cannot call write after a stream was destroyed #2545

Closed raviradadiya0142 closed 1 month ago

raviradadiya0142 commented 1 month ago

Please make sure you have searched for information in the following guides.

A screenshot that you have tested with "Try this API".

Node.js version : 16 "@google-cloud/storage": 7.11.3

Error during file upload NodeError: Cannot call write after a stream was destroyed 8|unipin-node-live | at doWrite (/home/unipin/unipin_nodejslive/node_modules/readable-stream/lib/_stream_writable.js:390:38) 8|unipin-node-live | at writeOrBuffer (/home/unipin/unipin_nodejslive/node_modules/readable-stream/lib/_stream_writable.js:381:5) 8|unipin-node-live | at Writable.write (/home/unipin/unipin_nodejslive/node_modules/readable-stream/lib/_stream_writable.js:302:11) 8|unipin-node-live | at HashStreamValidator.ondata (node:internal/streams/readable:809:22) 8|unipin-node-live | at HashStreamValidator.emit (node:events:517:28) 8|unipin-node-live | at addChunk (node:internal/streams/readable:368:12) 8|unipin-node-live | at readableAddChunk (node:internal/streams/readable:341:9) 8|unipin-node-live | at Readable.push (node:internal/streams/readable:278:10) 8|unipin-node-live | at HashStreamValidator._transform (/home/unipin/unipin_nodejslive/node_modules/@google-cloud/storage/build/cjs/src/hash-stream-validator.js:95:14) 8|unipin-node-live | at Transform._write (node:internal/streams/transform:175:8)

const file = cloudStorage.bucket(bucketName).file(fileName); return new Promise(async (resolve, reject) => { try { // Directly save the file content await file.save(fileData.buffer, { metadata: { contentType: fileData.mimetype, }, resumable: false, // Set to false as we're not using streams, validation:false });

    // Get the signed URL
    const [url] = await file.getSignedUrl({
      action: 'read',
      expires: '03-01-2500', // Set the appropriate expiration date
    });
    console.log(url,"url");

    resolve(url);
  } catch (err) {
    console.error('Error during file upload', err);
    reject(err);
  }
});
github-actions[bot] commented 1 month ago

Issue was opened with an invalid reproduction link. Please make sure the repository is a valid, publicly-accessible github repository, and make sure the url is complete (example: https://github.com/googleapis/google-cloud-node)