![](/img/trans.png)
[英]How to upload an image from a react native app (Expo) to a django server
[英]Unable to upload image/images to node js server with expo and react native
每當我嘗試從我的本機代碼向服務器發送表單數據或文件時,我都沒有在本機控制台中獲得 assets[0].fileSize 和 assets[0].fileName。 我的 React Native 代碼是:
const { status } = await Permissions.askAsync(Permissions.MEDIA_LIBRARY);
if (status !== "granted") {
// Handle permission denied
return;
}
const result = await ImagePicker.launchImageLibraryAsync({
mediaTypes: ImagePicker.MediaTypeOptions.Images,
});
console.log(result);
/**
I am getting this output from result:
{
assets: [
{
assetId: "1610",
base64: null,
duration: null,
exif: null,
height: 1840,
rotation: null,
type: "image",
uri: "file:///data/user/0/host.exp.exponent/cache/ExperienceData/%2540anonymous%252Fhelo-c554b96a-1355-4a71-8550-01d96488539b/ImagePicker/21bc87ec-4534-40d8-a86d-bd676ad9cbb2.jpeg",
width: 3264,
},
],
canceled: false,
cancelled: false,
};
**/
我正在使用 expo-image-picker 來選擇圖像。 在服務器端,我使用 multer().any() 來處理傳入服務器的文件。
我已經嘗試了更多的包:用於文件上傳的 xhr 但沒有用。
Expo 返回的 URI 是對設備 memory 上圖像數據的引用,您應該根據后端支持的數據類型上傳base64
或二進制數據。
為了簡單起見,我建議為expo-image-picker
picker 啟用 base64 - https://docs.expo.dev/versions/latest/sdk/imagepicker/#imagepickerasset
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.