-
-
Save foloinfo/0e82f1b7b3065d2807645f5a33b0a58a to your computer and use it in GitHub Desktop.
Workaround for uploading files from `assets-library` path on iOS with expo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// img | |
// { | |
// uri: '"assets-library://asset/asset.JPG?id=SOME_ID&ext=JPG"', | |
// md5: "some md5" | |
// } | |
// copy into cache dir first | |
const path = FileSystem.cacheDirectory + img.md5 | |
await FileSystem.copyAsync({ | |
from: img.uri, | |
to: path | |
}) | |
// read that and do upload | |
const file = await FileSystem.readAsStringAsync(path, { | |
encoding: FileSystem.EncodingTypes.Base64 | |
}) | |
const payload = { | |
title: 'some awesome photo', | |
image: file | |
} | |
fetch('somewhere', { | |
method: 'POST', | |
body: JSON.stringify(payload) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can get the local file system with the method:
this returns:
So the complete example is:
Hope its help!