Uploading Base64 to Firebase returns 413 status code

Viewed 223

(First question here e.e)

I'm currently trying to upload images to my Firebase Storage using the Firebase Admin SDK. The main difficulty is that the images are in base64.

Here is my function :

public uploadPicture (image: string, path: string): Promise<void> {
    const bucket = firebase.storage().bucket(process.env.FIREBASE_STORAGE_BUCKET)
    const file = bucket.file(path)
    const content = Buffer.from(image.replace(/^data:image\/(png|gif|jpeg);base64,/, ''), 'base64')
    file.save(content).then(() => console.log('done'))
}

I've been trying with some of my images, and got different errors depending on this image. In some case, the Firebase returned me a Error 413 (Request Entity Too Large) error, and in other Gaxios (probably a dependency of the Firebase SDK) gives me this error : Error: The maximum object length is 1024 characters, but got a name with 11596 characters.

Does someone know how to fix it ?

Thanks !

0 Answers
Related