简体   繁体   English

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

[英]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)
I'm looking for a solution only in the frontend, in this step the app not using the backend. 我只在前端寻找解决方案,在这一步中应用程序不使用后端。

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.

相关问题 React-Native:下载映像并将其转换为Base64映像 - React-Native: Download Image and convert it to Base64 Image React-Native:将图像 url 转换为 base64 字符串 - React-Native: Convert image url to base64 string PayloadTooLargeError:请求实体太大 - PayloadTooLargeError: request entity too large 功能反应本机:将 api 数据传递给组件时出现错误:PayloadTooLargeError:请求实体太大 - functional react native: when passing api data to render to the component gives an error: PayloadTooLargeError: request entity too large 如何在 React-Native 中将 base64 url 转换为图像(png/jpg)文件? - How can I convert a base64 url to an image(png/jpg) file, in React-Native? Gatsby 函数:PayloadTooLargeError:请求实体太大 - Gatsby Functions: PayloadTooLargeError: request entity too large Express: PayloadTooLargeError: 请求实体太大 - Express: PayloadTooLargeError: request entity too large react-native-camera 将图片 base64 转换为 jpeg - react-native-camera convert Image base64 to jpeg 将base64字符串转换为本机中的图像 - Convert base64 string to image in react native 通过file_put_contents将base64图像发布到文件夹时,从ajax得到413请求实体太大错误 - getting 413 Request Entity Too Large error from ajax when posting base64 image to folder by file_put_contents
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM