Javascript 如何解决;“文件名太长”;在React Native中将本地映像上载到Firestore和Firebase存储时?
我正在尝试将本地图像上载到云Firestore和Firebase存储 我使用的包是Javascript 如何解决;“文件名太长”;在React Native中将本地映像上载到Firestore和Firebase存储时?,javascript,reactjs,react-native,google-cloud-firestore,firebase-storage,Javascript,Reactjs,React Native,Google Cloud Firestore,Firebase Storage,我正在尝试将本地图像上载到云Firestore和Firebase存储 我使用的包是 从本地选择图像的步骤 将文件作为blob传输到Firebase存储 以下是我正在使用的两个函数: export const uploadPost = async (postImageUri) => { return new Promise(async(res, rej) => { const fs = RNFetchBlob.fs;
- 从本地选择图像的步骤
- 将文件作为blob传输到Firebase存储
export const uploadPost = async (postImageUri) => {
return new Promise(async(res, rej) => {
const fs = RNFetchBlob.fs;
fs.readFile(postImageUri,'hello','base64')
.then(async (data) => {
console.log('data from RNFetchBlob', data);
const storageRef = storage().ref(`posts/images`).child(`${data}`);
try {
storageRef.putFile(data,{contentType: 'image/jpeg'})
.on(
storage.TaskEvent.STATE_CHANGED,
snapshot => {
console.log('snapshot', snapshot.state);
console.log('progress', (snapshot.bytesTransferred)/(snapshot.totalBytes)*100);
if(snapshot.state === storage.TaskState.SUCCESS){
console.log('SUCCESS')
}
},
error => {
console.log('Image upload error', error);
rej(error)
},
() => {
storageRef.getDownloadURL()
.then((downLoadUri) => {
console.log('File available at: ', downLoadUri);
// addPostInfo
res(downLoadUri)
})
}
)
}catch{err => console.log(err) }
})
} )
}
export const addPostInfo = async (post) => {
console.log('post.postImageUri in addPostInfo', post.postImageUri.slice(10))
const remoteUri = await uploadPost(post.postImageUri);
return new Promise((res, rej) => {
firestore()
.collection('posts')
.add({
id: post.id,
createdAt: post.date,
description: post.description,
image: remoteUri,
location: post.checkin_location
})
.then(ref => {
console.log('Finish adding in addPostInfo', ref)
res(ref)
})
.catch(err => rej(err))
})
}
在主屏幕中,我直接将图像的路径发送到addPostInfo
:
const _onSharingPost = () => {
const postCreated = {
id: 'alkdgjhfa;oiughaoghus',
postImageUri: postImageUri,
date: _getCurrentDate(),
description: postDescription,
checkin_location: checkInLocation
}
postActions.addPostInfo(postCreated);
}
路径
如下所示:
content://com.google.android.apps.photos.contentprovider/0/1/content%3A%2F%2Fmedia%2Fexternal%2Fimages%2Fmedia%2F58/ORIGINAL/NONE/image%2Fjpeg/950379202
错误
...base64 string --> File name too long
它涉及到upLoadPost
函数的SUCCESS
部分,但仍然出现了错误
我已经试过了:
- 更改路径-->切断
内容://
- 使用XMLHttpRequest将blob发送到
以将其发送到存储器upLoadPost
base64
字符串。我知道我们需要把它改成水滴什么的,但我不知道怎么做。我在rn fetch blob
docs中找不到可以指定的位置
请帮帮我