Closed builtbyproxy closed 5 years ago
@builtbyproxy
Hello, could you tell me your string of img.uri
& react-native version?
Maybe you can provide code base for me?
Did you see my DEMO?
Hi @maxim-kolesnikov thanks for the quick response!
This is my uri: assets-library://asset/asset.HEIC?id=CC95F08C-88C3-4012-9D6D-64A413D254B3&ext=HEIC
and this is my react-native version: 0.57.0
Im sorry i cant send you any code base, I did see your demo and I mostly implement it how you have it, basically its as i wrote it in my initial post ^^
Thanks again!
I fixed this by going to my XCode and cleaning my build folder
CMD+K
@builtbyproxy hi, after cleaning my build folder, I restarted my metro bundler with resetted cache, and reinstalled my app, and got this error
Hey @HikaruKun Sorry Im not to sure, I do recall getting that error but I can't remember where You'll have to import platform and a few other things, but to use this I have:
Step 1:
import RNHeicConverter from "react-native-heic-converter";
Step 2: This is dependent on how you get your URL
const imgUrlTransform = (imgUrl = '', imgType = '') => {
if (Platform.OS === 'ios' && imgUrl.includes('ph://')) {
const formattedType = imgType === 'image/jpeg' ? 'JPG' : imgType.split('/')[1].toUpperCase();
const imgId = imgUrl.slice(5).split('/L0/')[0];
return `assets-library://asset/asset.${formattedType}?id=${imgId}&ext=${formattedType}`;
}
return imgUrl;
};
Step 3:
const imgTypeTransform = (imgType = '') => {
if (imgType) {
if (Platform.OS === "ios") {
const strSplit = imgType.split('.');
return `image/${ strSplit[strSplit.length - 1] }`;
}
return imgType;
}
return "image/jpg";
};
Step 3: Convert imgType and imgUrl, img is the image file itself
let imgType = imgTypeTransform(img.type);
let imgUrl = imgUrlTransform(img.uri, imgType);
Step 4:
if (imgType === "image/heic") {
await RNHeicConverter
.convert({ // options
path: imgUrl,
})
.then((result) => {
if (result.path) {
imgUrl = result.path;
imgType = "image/jpg";
}
});
}
Step 5: convert file to a buffer for upload to S3 or storage somewhere
const imageBuffer = await RNFetchBlob.fs.readFile(imgUrl, "base64").then((res) => new Buffer(res, "base64"));
Hello, im trying to use this module to convert an HEIC image to any other format, ideally jpeg.
However, I get the error above when I run the code below:
where I import
RNHeicConverter
as required.I have successfully linked RNHeicConverter and I am not seeing errors, this is joining a pretty beefy React-Native project and when I actually log RNHeicConverter to ensure it is functioning as intended it logs:
so it certainly doesn't look
undefined
I think this is happening because of how it pulls
RNHeicConverter
from nativeModules in your index.jsAny thoughts on what the fix may be? Thankyou!