R
R
Raybul2021-10-14 16:06:20
Node.js
Raybul, 2021-10-14 16:06:20

How to upload files to firebase with node js?

Hello everyone I am making a
simple application for node practice, and then there was a problem when sending data to firebase
, I have the following question:
When uploading files to Firebase from a node, the file is loaded but does not open, the loader just spins and that's it...
If you click on Create new access token, then everything opens normally)
How to create a token while sending the picture itself? In order not to create it manually, because. I plan to receive this image on the client later)

import bucket from '../firebaseConfig.js'

class FileService {
    saveFile(photo) {
        try {

            const blob = bucket.file(photo.name)

            const blobWriter = blob.createWriteStream({
                metadata: {
                    contentType: photo.mimetype,
                }
            })

            blobWriter.on('error', (err) => console.log (err))

            blobWriter.end (photo.data)

            return photo.name

        } catch (e) {
            console.log(e);
        }
    }
}
export default new FileService;

61682a9643fe0714472277.png
61682b3019256379942484.png
61682b373ea50504855349.png

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question