Skip to content

FileSystem.readAsStringAsync base64 result is huge #2703

@clems36

Description

@clems36

Environment

Expo CLI 2.3.8 environment info:
System:
OS: Windows 10
Binaries:
Yarn: 1.12.1 - C:\Users\Student\AppData\Roaming\npm\yarn.CMD
npm: 6.4.1 - C:\Users\Student\AppData\Roaming\npm\npm.CMD
IDEs:
Android Studio: Version 2.3.0.0 AI-162.4069837

Diagnostics report:
https://exp-xde-diagnostics.s3.amazonaws.com/emixis-82436675-9e02-4a6f-bb66-5660cf37149b.tar.gz

Steps to Reproduce

Call DocumentPicker.getDocumentAsync then FileSystem.readAsStringAsync to read the file as base64

const response: IDocumentPickerResponse = await DocumentPicker.getDocumentAsync({
    copyToCacheDirectory: false,
    type: '*/*',
});

const base64: string = await FileSystem.readAsStringAsync(
    response.uri,
    {
        encoding: FileSystem.EncodingTypes.Base64,
    });

console.log(base64.length);

Expected Behavior

My goal is to send the base64 to a server using webservices. I expected the base64 to be light enough to achieve that.

Actual Behavior

The base64 of a file that weights approx 3.9 Mo is 5 250 000 chars long (i can't even log it). When I try sending this to the server the request fails because the payload is too long.

Moreover, I'm getting this warning when saving it to redux:

chrome_2018-11-13_18-00-23

The app even crashes when the size of the file exceeds approx 8 Mo. Logcat's stack trace can be found here https://justpaste.it/6ss56

Is there a way to reduce the base64's size ?

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions