我想使用 feathersJS 将图像从 react-native 上传到 mongoDB
I want to upload an image from react-native to mongoDB using feathersJS
我正在使用 feathersJS 处理 react-native 上的电子商务应用程序项目我无法将图像上传到数据库中,我也在使用 react-native-blob 创建一个 blob 文件但是它不工作,它抛出 FileReader.readAsArrayBuffer is not implemented
的错误。
我只想上传一张图片,然后取回它,请帮助我使用 react-native。
https://github.com/feathersjs/feathers/issues/348
uploadImageFromDevice = () => {
const options = {
title: 'Select a Photo',
cancelButtonTitle: 'Cancel',
takePhotoButtonTitle: 'Take Photo…',
chooseFromLibraryButtonTitle: 'Choose from Library…'
};
ImagePicker.showImagePicker(options, (response) => {
console.log('Response = ', response);
if (response.didCancel) {
console.log('User cancelled image picker');
} else if (response.error) {
console.log('ImagePicker Error: ', response.error);
} else if (response.customButton) {
console.log('User tapped custom button: ', response.customButton);
} else {
{ this.storeImageToFeathers(response, response.fileName); }
}
});
}
storeImageToFeathers = (response, mime = ';BASE64') => new Promise((resolve, reject) => {
const uri = response.uri;
const uploadUri = Platform.OS === 'ios' ? uri.replace('file://', '') : uri;
const name = new Date().toString();
const imageRef = firebase.storage().ref('/photos/posts').child(name);
fs.readFile(uploadUri, 'base64')
.then(data => Blob.build(data, { type: `${mime};BASE64` }))
.then((blob) => {
console.log(blob);
client.service('image-upload').create({
uri: blob
}).then((res) => console.log(res))
.catch(err => console.log(err.message))
})
})
我正在使用 feathersJS 处理 react-native 上的电子商务应用程序项目我无法将图像上传到数据库中,我也在使用 react-native-blob 创建一个 blob 文件但是它不工作,它抛出 FileReader.readAsArrayBuffer is not implemented
的错误。
我只想上传一张图片,然后取回它,请帮助我使用 react-native。
https://github.com/feathersjs/feathers/issues/348
uploadImageFromDevice = () => {
const options = {
title: 'Select a Photo',
cancelButtonTitle: 'Cancel',
takePhotoButtonTitle: 'Take Photo…',
chooseFromLibraryButtonTitle: 'Choose from Library…'
};
ImagePicker.showImagePicker(options, (response) => {
console.log('Response = ', response);
if (response.didCancel) {
console.log('User cancelled image picker');
} else if (response.error) {
console.log('ImagePicker Error: ', response.error);
} else if (response.customButton) {
console.log('User tapped custom button: ', response.customButton);
} else {
{ this.storeImageToFeathers(response, response.fileName); }
}
});
}
storeImageToFeathers = (response, mime = ';BASE64') => new Promise((resolve, reject) => {
const uri = response.uri;
const uploadUri = Platform.OS === 'ios' ? uri.replace('file://', '') : uri;
const name = new Date().toString();
const imageRef = firebase.storage().ref('/photos/posts').child(name);
fs.readFile(uploadUri, 'base64')
.then(data => Blob.build(data, { type: `${mime};BASE64` }))
.then((blob) => {
console.log(blob);
client.service('image-upload').create({
uri: blob
}).then((res) => console.log(res))
.catch(err => console.log(err.message))
})
})