[英]How do I upload an image taken by React-Native-camera to Firebase storage?
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
您可以使用此示例代碼將您的圖片上傳到特定的 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); });
希望這對你有幫助。
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;
}
它奏效了,謝謝。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.