我正在尝试使用下一个代码在 expo react-native 应用程序中将图像转换为 base64:
import * as FileSystem from 'expo-file-system';
......
const base64 = await FileSystem.readAsStringAsync(result.uri, { encoding: 'base64' });
但是我得到这个错误:
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)
我该如何解决? 谢谢
最佳答案
我尝试了很多解决方案但都不适合我,然后我决定将图像大小调整为质量 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' });
关于javascript - 在 expo react-native 中将图像转换为 base64(仅在前端): PayloadTooLargeError: request entity too large,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67780721/