[英]convert image to base64 in expo react-native(only in the frontend): PayloadTooLargeError: request entity too large
I'm trying to convert the image to base64 in expo react-native app by using the next code:我正在尝试使用以下代码将图像转换为 expo react-native 应用程序中的 base64 :
import * as FileSystem from 'expo-file-system'; ...... const base64 = await FileSystem.readAsStringAsync(result.uri, { encoding: 'base64' });
but I get this error:但我收到此错误:
PayloadTooLargeError: request entity too large at readStream (C:\Users\rapha\AppData\Roaming\npm\node_modules\expo-cli\node_modules\@expo\dev-server\node_modules\raw-body\index.js:155:17) at getRawBody (C:\Users\rapha\AppData\Roaming\npm\node_modules\expo-cli\node_modules\@expo\dev-server\node_modules\raw-body\index.js:108:12) at read (C:\Users\rapha\AppData\Roaming\npm\node_modules\expo-cli\node_modules\@expo\dev-server\node_modules\body-parser\lib\read.js:77:3).... at Server.app (C:\Users\rapha\university\MA\third year\finalProject\argon-react-native-master\oneWay\node_modules\connect\index.js:51:37) at Server.emit (events.js:315:20) at Server.EventEmitter.emit (domain.js:483:12) at parserOnIncoming (_http_server.js:790:12) at HTTPParser.parserOnHeadersComplete (_http_common.js:119:17)
how can I fix it?我该如何解决? thanks
谢谢
I tried many solutions but nothing for me then I decided to resize the image to quality 0.5 and it work to me我尝试了很多解决方案,但对我没有任何帮助,然后我决定将图像大小调整为 0.5 质量,它对我有用
let result = await ImagePicker.launchImageLibraryAsync({ mediaTypes:await ImagePicker.MediaTypeOptions.All, allowsEditing:true, aspect:[4,3], quality:0.5 }).... const base64 = await FileSystem.readAsStringAsync(result.uri, { encoding: 'base64' });
The problem is not this line, it works properly.问题不在于这条线,它工作正常。 It is the fetch API or the server file size limit.
它是获取 API 或服务器文件大小限制。
con la libreria https://docs.expo.dev/versions/latest/sdk/imagepicker/ podes hacerlo sin usar la otra.. con la libreria https://docs.expo.dev/versions/latest/sdk/imagepicker/podes hacerlo sin usar la otra..
const result = await ImagePicker.launchImageLibraryAsync({ base64: true, quality: 1 });常量结果 = 等待 ImagePicker.launchImageLibraryAsync({ base64: true, 质量: 1 });
console.log(result.base64) console.log(result.uri) console.log(result.base64) console.log(result.uri)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.