firebase-js-sdk
firebase-js-sdk copied to clipboard
Expo Image Picker data url cannot be uploaded with error "String does not match format 'base64'"
- Operating System version: iOS simulator 15.0
- Browser version: _____
- Firebase SDK version: ^9.9.2
- Firebase Product: storage
Steps to reproduce:
Use Expo Image Picker to get the base64 encoding of a starter photo in the photo library. Convert the base64 encoding into a data uri by prepending it with "data:image/jpeg;base64," and enter it into uploadString as format data_url. It will return the following error: Firebase Storage: String does not match format 'base64': Invalid character found (storage/invalid-format)
import * as ImagePicker from "expo-image-picker";
import { getStorage, ref, uploadString } from "firebase/storage";
const storage = getStorage();
.
.
.
ImagePicker.launchImageLibraryAsync({
mediaTypes: ImagePicker.MediaTypeOptions.All,
allowsEditing: true,
aspect: [4, 3],
quality: 1,
base64: true,
}).then((result) => {
if (result.uri) {
const imageRef = ref(storage, `/photoURLs/randomID`);
return uploadString(
imageRef,
"data:image/jpeg;base64," + result.base64,
"data_url"
);
}
return Promise.resolve();
});