Closed snowfluke closed 1 year ago
Alright thanks, I've found the solution. For anyone that stumble into the same problem, here's the solution:
import RNFS from 'react-native-fs'; import {Platform} from 'react-native';
const createTempImage = async base64String => { try {
let base64 = base64String.replace('data:image/png;base64,', '');
const fileName = `${Date.now()}.png`;
const path = `${RNFS.TemporaryDirectoryPath}/${fileName}`;
await RNFS.writeFile(path, base64, 'base64');
const image = {
uri: Platform.OS == 'ios'? path: 'file://' + path,
name: fileName,
type: 'image/png',
};
return image
} catch (error) {
console.log(error);
}
};
You might need to add `file://` in front of the URI, and also specify the mime-type. I'm just hardcoded it to png.
How to get the blob instead of the Base64 string so that we can append it to FormData