Контекст:
У меня есть конечная точка API, которая обслуживает файлы .stl, хранящиеся в общедоступном c хранилище Google Cloud Storage. До этой недели все работало нормально. Я могу пройти весь мой код с помощью отладчика. О данном модуле NPM в моем проекте даже нет ссылок. Я попытался использовать точный код в документации Googles для загрузки и получил то же исключение: https://github.com/googleapis/nodejs-storage/blob/master/samples/downloadFile.js
Что я пробовал
npm rebuild @google-cloud/storage
и различные способы использования одного и того же пакета Google npm.
Вопросы:
1.) Если не поймать, поймать исключение для предотвратить взлом sh?
2.) У кого-нибудь есть идеи по поводу обходного пути?
Файл: https://storage.cloud.google.com/fancy_induction_ui/1inX1in.stl
Код:
getFile: async (req, res) => {
try {
const fileName = req.param('file');
res.setHeader('Content-Type', 'application/octet-stream');
res.setHeader('Content-Disposition', 'attachment; filename=' + fileName + '');
const storage = new Storage();
let file = await storage.bucket('fancy_induction_ui').file(fileName).createReadStream();
file.pipe(res);
} catch (e) {
res.status(500).json({message: 'Something is wrong!', err: e.message});
}
}
Stacktrace:
path/to/code/node_modules/readable-stream/lib/_stream_writable.js:317
var isBuf = !state.objectMode && _isUint8Array(chunk);
^
TypeError: Cannot read property 'objectMode' of undefined
at DestroyableTransform.Writable.write (path/to/code/node_modules/readable-stream/lib/_stream_writable.js:317:22)
at PassThrough.ondata (_stream_readable.js:714:22)
at PassThrough.emit (events.js:321:20)
at PassThrough.EventEmitter.emit (domain.js:482:12)
at PassThrough.Readable.read (_stream_readable.js:512:10)
at flow (_stream_readable.js:989:34)
at resume_ (_stream_readable.js:970:3)
at processTicksAndRejections (internal/process/task_queues.js:84:21)