Hey I have found out how to upload into the firebase storage:
admin.initializeApp({ credential: secret, databaseURL: secret, storageBucket: secret, }); var bucket = admin.storage().bucket(); const uploadToFireStorage = (filename, query, fileType, imageURL) => { bucket.upload(filename).then(console.log("uploaded")); };
As you can see with my bucket.upload function I can upload to firebase storage but it gets uploaded into the root folder and I want to put it under /foodImages/myfile.png for example Any ideas ?
Advertisement
Answer
Actually Google Cloud Storage does not have genuine “folders”.
In the Cloud Storage console, the files in your bucket are presented in a hierarchical structure of folders (just like the file system on your local hard disk) but this is just a way of presenting the files: there aren’t genuine folders/directories in a bucket. The Cloud Storage console just uses the different parts of the file paths to “simulate” a folder structure, by using the “/” delimiter character.
So, you need to use an UploadOptions
object as shown in the doc with a destination
property which is defined with some “/”, as follows:
const destinationFilename = "folder1/myfile.png"; bucket.upload('...', { destination: destinationFilename });