0
votes
var storageRef = firebase.storage().ref();
var ref = storageRef.child("filename.pdf");
let answ = result.toString("base64");

ref.putString(answ, "base64").then(function (snapshot) {
  console.log("Uploaded a base64 string!");
});

I'm using this "result.toString("base64")" for attachment file to email likle string base64, but cant use that for saving to Firebase Storage

Full error:

[FirebaseStorageError [FirebaseError]: Firebase Storage: String does not match format 'base64': Invalid character found (storage/invalid-format)] { code: 'storage/invalid-format', customData: { serverResponse: null } } I got always this error and googled too much, but still haven't any information. I "result.toString("base64")" to attach this like base64 string for sending email and it's working, but not for saving to storage. Could someone help, please?

1
I've tryed. Its about jpeg and I dont know what different between pdf. But still stuked(Vyacheslav Tarshevskiy

1 Answers

0
votes

Yo can try this:

 let Reader = new FileReader()
 Reader.onload = (event)=>{
      let result = event.target.result
      console.log(result)
                            
      storage.child("files/"+file.name).putString(result,"data_url", 
      {contentType:"application/pdf"}).then(function(snapshot) {
         console.log(snapshot);
      });
 }
 Reader.readAsDataURL(file) // file is blob

I hope this can be helpful, best regards!