[英]React Native Possible Unhandled Promise Rejection (id: 0):
我正在嘗試從博覽會相機保存圖片。 之后,我將把這張照片發送到cloudinary。 因此,我需要base64屬性。 但是我有一個問題。
takePictureAndCreateAlbum = async () => {
const { uri } = await this.camera.takePictureAsync({
base64: true
}).then(data => {
return (
this.setState({
data
}),
console.log("data", data)
)
}).catch(err => {
throw error;}
)
const asset = await MediaLibrary.createAssetAsync(uri);
MediaLibrary.createAlbumAsync('Expo', asset)
.then(() => {
Alert.alert('Album created!')
})
.catch(error => {
Alert.alert('An Error Occurred!')
});
this.sendCloudinary(this.state.data)
};
當我嘗試保存圖片時,出現以下錯誤:
可能的未處理的承諾拒絕(標識:0):
TypeError:無法讀取未定義的屬性“ uri”
我檢查了另一個問題和答案。 但是我沒有找到解決方案。 我該如何解決?
您可能想要更多類似的東西。
takePictureAndCreateAlbum = async () => {
const { uri } = await this.camera
.takePictureAsync({
base64: true
})
.then(data => {
this.setState({
data
}),
console.log("data", data);
return data;
})
.catch(err => {
throw error;
});
const asset = await MediaLibrary.createAssetAsync(uri);
MediaLibrary.createAlbumAsync("Expo", asset)
.then(() => {
Alert.alert("Album created!");
})
.catch(error => {
Alert.alert("An Error Occurred!");
});
this.sendCloudinary(this.state.data);
};
在上面發布的示例中,您將返回this.setState和控制台日志的組合,此時takePictureAsync
解析初始takePictureAsync
承諾時返回數據。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.