我正在使用 expo-image-picker,如果我在 android 模擬器中選擇一個影像并保存它,當我用我的真實設備進入程式時,我看不到我從模擬器中保存的影像。換句話說,無論我使用哪種設備保存圖片,它都只會出現在該設備上。它不會出現在其他設備上。我該如何解決這個問題?
我正在使用 API 進行資料庫操作(使用 axios)
這是代碼
const PickImage = async () => {
allowPhotoRequests()
let result = await ImagePicker.launchImageLibraryAsync({
mediaTypes: ImagePicker.MediaTypeOptions.All,
allowsEditing: true,
aspect: [4, 3],
quality: 1,
base64: true
})
if (!result.cancelled) {
setImage(result.uri) // I think I have to do something here
}
提交代碼:
const addPet = async () => {
try {
petApi.post('/', {
userId: userId,
Age: age,
Weight: weight,
userName: currentUser,
userPhone: currentUserPhone,
petImage: image,
city: city,
district: district
})
.then(function (response) {
alert('Success!')
})
}
catch (error) {
console.log(error);
}
}
示例影像輸出:
file:///data/user/0/host.exp.exponent/cache/ExperienceData/%40yas1nkiziltas%2FPettyApp/ImagePicker/cb2923b3-5de8-4692-8244-0ce9b987001a.jpg
uj5u.com熱心網友回復:
在使用此 Expo 時,有兩種方法可以解決此問題:
- 提交影像資料為
base64 - 查看后端 API 支持
BLOB,您可以BLOB使用下面的代碼獲取。
const blob = await new Promise((resolve, reject) => {
const xhr = new XMLHttpRequest();
xhr.onload = function () {
resolve(xhr.response);
};
xhr.onerror = function (e) {
reject(new TypeError("Network request failed"));
};
xhr.responseType = "blob";
xhr.open("GET", [YOUR_FILE_PATH_URI], true);
xhr.send(null);
});
// Use blob after fetch
console.log(blob)
// We're done with the blob, close and release it
blob.close();
uj5u.com熱心網友回復:
您正在 patApi 資料庫中為特定用戶 ID 保存 petImage。在任何設備上,要獲取該影像,您都需要再次獲取此資料,我看不到您在發布后獲取此影像資料。這是您缺少的部分。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/398863.html
上一篇:計算遞回反應組件中兒童的數量
