How to convert file:/// path to http path in react-native expo?

26 views Asked by At

I can run the code below and it works normally. imageAssetPath.uri's path is "http://10...".

let image = require("./apple-banana.jpg");
const imageAssetPath = Image.resolveAssetSource(image);
const response = await fetch(imageAssetPath.uri, {}, { isBinary: true });

However, when I change imageAssetPath.uri to a path that is not http, for example: "file:///data/user....", it will not work. Shows an error Network request failed. How do I resolve this issue? I would happily accept any solution as long as it works.

I was wondering if it is possible to convert the "file:///" path to an "http" path.

For reference, the end result would be to use it in this code.

const imageDataArrayBuffer = await response.arrayBuffer();
const imageData = new Uint8Array(imageDataArrayBuffer);
let imageTensor = decodeJpeg(imageData);
0

There are 0 answers