Closed luizaugustoventura closed 2 years ago
Update with solution
Alright guys, after a long time of research, me and a colleague got to a solution which may not be the best but does what we expected.
First of all, one thing that was discovered is that we have to divide the problem in two, because we actually had two problems.
file://
and could be rendered by WebView. That's the code we used to do this: export default function getImageNameFromUrl(imageUrl = "") {
if (imageUrl) {
const splittedImageUrl = imageUrl.split('/');
return splittedImageUrl.pop();
}
return null;
};
export default async function copyAssetsFileIOSAndReturnURI(remoteURL = '', localURI = '') {
try {
if (remoteURL && localURI) {
const imageName = getImageNameFromUrl(remoteURL);
const imgPath = await RNFS.copyAssetsFileIOS(localURI, RNFS.TemporaryDirectoryPath+imageName, 0, 0);
return imgPath;
}
return null;
} catch (err) {
console.log(err);
return null;
}
}
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Description
As you guys probably know, there was a problem previously with this library not rendering local images on Android. Now, I'm facing the exact same issue on iOS, with a difference that I can use static images like
assets/src/assets/images/logo.png
. But when the images start with something likefile:///
,storage://
,ph://
it simply does not get rendered.Whtat I'm doing is trying to generate a PDF report file, the static image is the logo of the company and the local image which is not being rendered is an image saved to the phone's storage with either Image Picker or Camera Roll. The React Native Image component displays the image perfectly, so I don't think I'm using the wrong path.
What have I tried so far?
file:///
orstorage://
orph://
from the begining of the path string;ph://
without an extension. I tried to put the extension manually, and still does not make any difference;RNFetchBlob.fs.base64.encode(path)
), but still no success.Devices
Environment
node: 12.22.7 npm: 6.14.15 react: 16.9.0 react-native: 0.61.5 react-native-html-to-pdf: ^0.11.0