イメージファイルをbase64またはblobとしてエンコードするのに使用しようとしていますが、どちらも動作していません。また、画像選択ツールの管理にはhttps://github.com/react-community/react-native-image-pickerを使用しています。React Native + Firebase Storage:base64とblobが動作しない
1を試してみてください:Firebase Storage: String does not match format 'base64': Invalid character found
は2を試してみてください:ブロブはhttps://github.com/wkh237/react-native-fetch-blob
const uri = file.uri;
const uploadUri = Platform.OS === 'ios' ? uri.replace('file://', '') : uri
data = RNFetchBlob.fs.readFile(uploadUri, 'base64')
blob = RNFetchBlob.polyfill.Blob.build(data, { type: 'application/octet-stream;BASE64' })
const uniqueId = uuid.v4();
const firebaseRef = firebase.storage().ref('images').child(`${uniqueId}.jpg`)
return Observable.fromPromise(firebaseRef.put(blob, { contentType: 'application/octet-stream;BASE64' }));
})
を使用してbase64文字列
const blah = uuid.v4();
firebase
.storage()
.ref('images')
.child(`${blah}.jpg`)
.putString(file.data, 'base64', { contentType: 'image/jpeg' })
を返すことを想定しかし、これがスローされる画像ピッカーの.data
方法を、使用してただし、返品中です:Firebase Storage: Invalid argument in
put at index 0: Expected Blob or File.
3試してみてください:base64でhttps://github.com/wkh237/react-native-fetch-blob
const uri = file.uri;
const uploadUri = Platform.OS === 'ios' ? uri.replace('file://', '') : uri
data = RNFetchBlob.fs.readFile(uploadUri, 'base64')
const uniqueId = uuid.v4();
const firebaseRef = firebase.storage().ref('images').child(`${uniqueId}.jpg`)
const metadata= {
contentType: 'image/jpeg',
};
firebaseRef.putString(data, 'base64', metadata);
を使用してしかし、これは再びスロー:Firebase Storage: String does not match format 'base64': Invalid character found
誰もが私が間違ってやっている知っていますか?
私はこれと同じ問題に実行していますよ。本当に変わったことは、反応するネイティブデバッガがオンになっているときに.dataが機能することです。 –