2021年3月18日星期四

Error while uploading file to Firebase Storage using Firebase Cloud Functions

I'm trying to upload a pdf to Firebase Storage using Firebase Cloud Functions, I have this post function with the following body:

{      "email":"gianni@test.it",      "name":"Gianni",      "surname":"test",      "cellphone":"99999999",      "data":       {      "file":BASE_64,      "fileName":"test.pdf"      }  }  

I want to save the base64 value in the "file" field and name as "fileName" field, here is the function that saves the file:

const admin = require("firebase-admin");    /**     * Create a new file in the storage.     * @param {Object} wrapper [File to upload in the storage.]     * @param {String} path [Path to upload file to.]     * @return {object} [Containing the response]     */    postStorageFileAsync(wrapper, path) {      return new Promise((res, rej)=>{        System.prototype.writeLog({          wrapper: wrapper,          path: path,        });        const newFile = admin.storage().bucket().file(wrapper.path);        return newFile.save(wrapper.file).then((snapshot) => {          System.prototype.writeLog({snap: snapshot});          return snapshot.ref.getDownloadURL().then((downloadURL) => {            System.prototype.writeLog({fileUrl: downloadURL});            return res({code: 200, data: {url: downloadURL}});          });        }).catch((err)=>{          System.writeLog(err);          return rej(err);        });      });    }  

But I'm getting:

postCurriculum

Error: A file name must be specified. at Bucket.file (/workspace/node_modules/@google-cloud/storage/build/src/bucket.js:1612:19) at /workspace/Firebase/Firebase.js:43:48 at new Promise () at Object.postStorageFileAsync (/workspace/Firebase/Firebase.js:38:12) at /workspace/PersistanceStorage/PersistanceStorage.js:407:35 at processTicksAndRejections (internal/process/task_queues.js:97:5)

Aside for the error itself, does anybody has a working example/tutorial link on how to upload files to firebase storage through functions? The documentation is really lacking.

Thanks

https://stackoverflow.com/questions/66697996/error-while-uploading-file-to-firebase-storage-using-firebase-cloud-functions March 19, 2021 at 03:38AM

没有评论:

发表评论