Я пытаюсь загрузить файл документа из локального хранилища файлов firebase, используя node.js.
Но я получаю сообщение об ошибке:
Ошибка: не найдена
Ниже приведен мой код.Не могли бы вы помочь мне в этом.
const keyFilename="./xxxxxxxx.json";
const multer = Multer({
fileFilter: function(req, file, cb){
checkFiletype(file, cb)
},
storage: Multer.memoryStorage(),
limits: {
fileSize: 5 * 1024 * 1024 // no larger than 5mb, you can change as needed.
}
});
const storage = googleStorage({
projectId: 'xxxx' ,
keyFilename :keyFilename
});
const bucket = storage.bucket("gs://xxxx/xxxx");
const uploadImageToStorage = (file) => {
let prom = new Promise((resolve, reject) => {
if (!file) {
reject('No image file');
}
console.log('filw',file);
let newFileName = `${file.originalname}_${Date.now()}`;
let fileUpload = bucket.file(newFileName);
const blobStream = fileUpload.createWriteStream({
metadata: {
contentType: file.mimetype
}
});
blobStream.on('error', (error) => {
console.log(error);
reject('Something is wrong! Unable to upload at the moment.');
});
blobStream.on('finish', () => {
// The public URL can be used to directly access the file via HTTP.
const url = util.format(`https://storage.googleapis.com/${bucket.name}/${fileUpload.name}`);
resolve(url);
});
blobStream.end(file.buffer);
});
return prom;
}
Ошибка: ниже приведена ошибка, с которой я сталкиваюсь при загрузке файла в хранилище файлов Firebase.
Error: Not Found
at Request._callback (C:\Users\rkanumetta\Desktop\uploadapi\node_modules\gcs
-resumable-upload\build\src\index.js:248:33)
at Request.self.callback (C:\Users\rkanumetta\Desktop\uploadapi\node_modules
\request\request.js:185:22)
at emitTwo (events.js:126:13)
at Request.emit (events.js:214:7)
at Request.<anonymous> (C:\Users\rkanumetta\Desktop\uploadapi\node_modules\r
equest\request.js:1157:10)
at emitOne (events.js:116:13)
at Request.emit (events.js:211:7)
at IncomingMessage.<anonymous> (C:\Users\rkanumetta\Desktop\uploadapi\node_m
odules\request\request.js:1079:12)
at Object.onceWrapper (events.js:313:30)
at emitNone (events.js:111:20)
Something is wrong! Unable to upload at the moment.