Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot call write after a stream was destroyed #2546

Open
raviradadiya0142 opened this issue Oct 24, 2024 · 2 comments
Open

Cannot call write after a stream was destroyed #2546

raviradadiya0142 opened this issue Oct 24, 2024 · 2 comments
Labels
api: storage Issues related to the googleapis/nodejs-storage API. needs more info This issue needs more information from the customer to proceed.

Comments

@raviradadiya0142
Copy link

PLEASE READ: If you have a support contract with Google, please create an issue in the support console instead of filing on GitHub. This will ensure a timely response.

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);
  }
});
@product-auto-label product-auto-label bot added the api: storage Issues related to the googleapis/nodejs-storage API. label Oct 24, 2024
@raviradadiya0142
Copy link
Author

error Error: Failed to upload file: Cannot call write after a stream was destroyed
at Writable. (/home/unipin/unipin_nodejslive/src/utils/fileUpload.js:199:20)
at Writable.emit (node:events:529:35)
at emitErrorNT (node:internal/streams/destroy:151:8)
at emitErrorCloseNT (node:internal/streams/destroy:116:3)
at process.processTicksAndRejections (node:internal/process/task_queues:82:21)

@ddelgrosso1
Copy link
Contributor

@raviradadiya0142 how frequently are you running into this problem? I'm assuming the exception gets thrown during the save call but just want to make sure this code never actually reaches the getSignedUrl portion, is that accurate? Any different behavior if you use resumable: true or validation not set to false?

@ddelgrosso1 ddelgrosso1 added the needs more info This issue needs more information from the customer to proceed. label Oct 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: storage Issues related to the googleapis/nodejs-storage API. needs more info This issue needs more information from the customer to proceed.
Projects
None yet
Development

No branches or pull requests

2 participants