在expo react-native中将图像转换为base64(仅在前端):PayloadTooLargeError:请求实体太大

use*_*984 3 javascript base64 reactjs react-native expo

我正在尝试使用以下代码在 expo react-native 应用程序中将图像转换为 base64:

import * as FileSystem from 'expo-file-system';
......

const base64 = await FileSystem.readAsStringAsync(result.uri, { encoding: 'base64' });
Run Code Online (Sandbox Code Playgroud)

但我收到此错误:

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)
Run Code Online (Sandbox Code Playgroud)
我只在前端寻找解决方案,在这一步中应用程序不使用后端。

我该如何修复它?谢谢

use*_*984 5

我尝试了很多解决方案,但没有任何效果,然后我决定将图像大小调整为质量 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' });
Run Code Online (Sandbox Code Playgroud)