For android its working but for ios im getting undefined
**
LOG Image downloaded at: undefined/image_1716340223058.png
**
import React, {useEffect} from 'react';
import {
View,
TextInput,
TouchableOpacity,
Text,
StyleSheet,
Alert,
} from 'react-native';
import RNFS from 'react-native-fs';
const App = () => {
const image =
'https://images.pexels.com/photos/785080/pexels-photo-785080.jpeg?auto=compress&cs=tinysrgb&fit=crop&h=1200&w=800';
const downloadImageRemote = () => {
let date = new Date();
let image_URL = image;
let ext = '.png';
let PictureDir = RNFS.DownloadDirectoryPath;
let imageName =
'image_' + Math.floor(date.getTime() + date.getSeconds() / 2) + ext;
let imagePath = `${PictureDir}/${imageName}`;
RNFS.downloadFile({
fromUrl: image_URL,
toFile: imagePath,
background: true,
discretionary: true,
})
.promise.then(res => {
console.log('Image downloaded at:', imagePath);
Alert.alert('Image Downloaded Successfully.');
})
.catch(error => {
console.error('Download failed:', error);
Alert.alert('Download failed. Please try again later.');
});
};
return (
<View style={styles.container}>
<TextInput style={styles.input} value={image} placeholder="Enter text" />
<TouchableOpacity
style={styles.button}
onPress={() => downloadImageRemote()}>
<Text style={styles.buttonText}>Submit</Text>
</TouchableOpacity>
</View>
);
};
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
},
input: {
borderWidth: 1,
borderColor: 'black',
borderRadius: 5,
padding: 10,
width: '80%',
marginBottom: 20,
},
button: {
backgroundColor: 'blue',
padding: 10,
borderRadius: 5,
},
buttonText: {
color: 'white',
fontSize: 18,
},
});
export default App;
Can anyone help?
I trid changing the path but not woking
I tride loggin this Image downloaded at: /Users/monishreddy/Library/Developer/CoreSimulator/Devices/DF04A1EA-BC7E-49F9-BB47-24EC599C9CD5/data/Containers/Data/Application/65A998A4-E032-4F3D-9A1A-64137D1786F2/Library/image_1716340650288.png
Monish reddy is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.