1

I am getting the image path in the response from API and on the click of thumbnail I want to open the image in browser.

user11426267
  • 361
  • 4
  • 7
  • 13

2 Answers2

1

If the image path is full url to the image file, then you can open it on browser app with Linking.

import { Linking } from 'react-native';

Linking.openURL(url);

https://facebook.github.io/react-native/docs/linking#openurl

edited:

enter image description here

chin8628
  • 446
  • 7
  • 15
  • That is the problem instead of url I got local storage path of image. – user11426267 Oct 04 '19 at 08:02
  • Does the image file is on your app? – chin8628 Oct 04 '19 at 08:02
  • No I don't have image on my app. When the user clicks on thumbnail the API is hit and in that I get a response of its path. Example:"D:\\code\\1\\image" – user11426267 Oct 04 '19 at 08:07
  • But, the image file is on your mobile phone in local storage? – chin8628 Oct 04 '19 at 08:10
  • The image is on local storage. – user11426267 Oct 04 '19 at 08:14
  • You can open the image path which is in local storage via browser. I've attached the screenshot of my phone display a image file on chrome app. – chin8628 Oct 04 '19 at 08:19
  • Ok I will try. Thankyou – user11426267 Oct 04 '19 at 08:23
  • What if I made my pc as server and the image is stored in some drive of pc and I return that path through API. What will be the scenario. I tried normal approach but it gives error – user11426267 Oct 04 '19 at 08:27
  • That may not be a good solution... Your server should return the url to image files via api instead of giving local path. Can you explain whole scenario? What you want to achieve? – chin8628 Oct 04 '19 at 08:34
  • Actually i am building app where the post and images are stored on local server and onClick I want to redirect it into browser for both image and post – user11426267 Oct 04 '19 at 08:52
  • Imo, you should implement the system as normal online backend-client. First, implement your backend server for serve image file via web server. Second, make your api server return path of image file to client as URL path in order to let your client access image file from local network. URL in local network may be "192.168.1.28/images/abc.jpg". Finally, let your client connect api server and receive the image file, then open it on browser app. Sorry for my broken english. I'm not native speaker. – chin8628 Oct 04 '19 at 09:08
1

Use react-native-file-viewer and download that file than open it