13.7 C
London
Wednesday, May 22, 2024

reactjs – I’m attempting to obtain an Picture utilizing URL in react native for android and IOS


For android its working however for ios im getting undefined

**
LOG Picture downloaded at: undefined/image_1716340223058.png
**

import React, {useEffect} from 'react';
import {
  View,
  TextInput,
  TouchableOpacity,
  Textual content,
  StyleSheet,
  Alert,
} from 'react-native';
import RNFS from 'react-native-fs';

const App = () => {
  const picture="https://photographs.pexels.com/images/785080/pexels-photo-785080.jpeg?auto=compress&cs=tinysrgb&match=crop&h=1200&w=800";

  const downloadImageRemote = () => {
    let date = new Date();
    let image_URL = picture;
    let ext=".png";
    let PictureDir = RNFS.DownloadDirectoryPath;
    let imageName="image_" + Math.ground(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('Picture downloaded at:', imagePath);
        Alert.alert('Picture Downloaded Efficiently.');
      })
      .catch(error => {
        console.error('Obtain failed:', error);
        Alert.alert('Obtain failed. Please strive once more later.');
      });
  };

  return (
    <View fashion={types.container}>
      <TextInput fashion={types.enter} worth={picture} placeholder="Enter textual content" />
      <TouchableOpacity
        fashion={types.button}
        onPress={() => downloadImageRemote()}>
        <Textual content fashion={types.buttonText}>Submit</Textual content>
      </TouchableOpacity>
    </View>
  );
};

const types = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'heart',
    alignItems: 'heart',
  },
  enter: {
    borderWidth: 1,
    borderColor: 'black',
    borderRadius: 5,
    padding: 10,
    width: '80%',
    marginBottom: 20,
  },
  button: {
    backgroundColor: 'blue',
    padding: 10,
    borderRadius: 5,
  },
  buttonText: {
    coloration: 'white',
    fontSize: 18,
  },
});

export default App;

Can anybody assist?
I trid altering the trail however not woking

I tride loggin this Picture downloaded at: /Customers/monishreddy/Library/Developer/CoreSimulator/Gadgets/DF04A1EA-BC7E-49F9-BB47-24EC599C9CD5/knowledge/Containers/Knowledge/Software/65A998A4-E032-4F3D-9A1A-64137D1786F2/Library/image_1716340650288.png

Latest news
Related news

LEAVE A REPLY

Please enter your comment!
Please enter your name here