javascript - 在 expo react-native 中将图像转换为 base64(仅在前端): PayloadTooLargeError: request entity too large

标签 javascript reactjs react-native base64 expo

我正在尝试使用下一个代码在 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/

相关文章:

javascript - 在网页上的文本选择上创建悬停按钮

javascript - Axios 详细地返回嵌套对象作为响应

javascript - Nodejs 调用函数

reactjs - 无法从 'index.js' 解析自定义组件的模块

javascript - React - useImperativeHandle 暴露的属性重叠

javascript - 无法通过 Template Bottle 将数据发送到 Javascript

javascript - 当我想要 dockerize 我的 nextjs 项目时出现问题

reactjs - Next.js 路线 : Dynamic vs exact

reactjs - 在根项目中找不到任务 'bundleReleaseJsAndAssets'

ios - ld : library not found for -lRCTAnimation