vendredi 23 avril 2021

How to upload file (selected by user) to Firebase Storage using node.js?

I am working on a project (web, node.js, Firebase functions, hosting and storage) that needs the following functionality:

  • user selects file via
  • other button runs a script that aims to upload selected file(s) to storage.

The problem is that - according to documentation of google storage admin with node.js: https://googleapis.dev/nodejs/storage/latest/Bucket.html#upload - file can only be uploaded using a path e.g.:

const options = {
  destination: bucket.file('existing-file.png'),
  resumable: false
};

bucket.upload('local-img.png', options, function(err, newFile) {
  // Your bucket now contains:
  // - "existing-file.png" (with the contents of `local-img.png')

}); 

BUT file input field is not allowed to let the browser know what the exact path is. It allows me to know:

  • the file name
  • the file URL (URL.createObjectURL(...) -» "blob:https://mis...")
  • the file itself as a blob

Summing it up the page cannot hand over the variant the upload mechanism can handle.

Does anybody know the way how to do this?




Aucun commentaire:

Enregistrer un commentaire