takePicture = async function() {
if (this.camera) {
const options = { quality: 0.5, base64: true, mirrorImage: true };
const data = await this.camera.takePictureAsync(options)
this.setState({path: data.uri})
}
}takePicture是捕获图像的函数。现在,我想保存捕获的图像并将其上传到Firebase存储。
this.setState({ path : data.uri})将路径更新为单击图像的位置。
如何使用react native fetch blob在firebase存储中上传我的图像?请帮帮忙
我当前使用的是react-native-camera - ^1.6.3和firebase - ^5.0.3
发布于 2018-12-21 22:23:07
您可以使用此示例代码将您的图片上传到特定的api。
var data = new FormData();
data.append('file', { uri: data.uri, name: 'picture.jpg', type: 'image/jpg' });
// Create the config object for the POST
const config = {
method: 'POST',
body: data
};
fetch('URL', config).then(responseData => {
// Log the response form the server // Here we get what we sent to Postman
back
console.log(responseData);
})
.catch(err => { console.log(err); });希望这能对你有所帮助。
发布于 2020-03-21 04:09:19
async function uploadFile() {
const data = new FormData();
data.append('file', { uri: data.uri, name: 'anyname.jpg', type: 'image/jpg' });
const response = await axios.post('URL', data);
const { id, url } = response.data;
}它起作用了,谢谢。
https://stackoverflow.com/questions/53864677
复制相似问题