最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - convert image to base64 in expo react-native(only in the frontend): PayloadTooLargeError: request entity too large

programmeradmin2浏览0评论

I'm trying to convert the image to base64 in expo react-native app by using the next code:

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

const base64 = await FileSystem.readAsStringAsync(result.uri, { encoding: 'base64' });

I'm trying to convert the image to base64 in expo react-native app by using the next code:

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 parserOnIning (_http_server.js:790:12)
    at HTTPParser.parserOnHeadersComplete (_http_mon.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

Share Improve this question asked May 31, 2021 at 22:17 user5869984user5869984 911 gold badge1 silver badge6 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 5

I tried many solutions but nothing for me then I decided to resize the image to quality 0.5 and it work to me

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.

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论