0

In my backend i have route to get images that called /images And route to upload images that called images/new/

And i used multer to upload the images. I created path to multer that called /uploads

now my question is When i call with axios from the frontend. If i want to get the images what i should put in the url?

Right now i write : <Image source={require("../../server/uploads/" + item.imageUrl)} /> (image won't show up & get syntax error). 2: <Image source={"http:8080//uploads/k2.jpg")} /> (image dont show up)

And when i doing post method which url i need to send?


I used react native nodejs mongoose

Roei Grinshpan
  • 395
  • 1
  • 5
  • 19

1 Answers1

1

you can use the template to add image URL to the image

<Image source={require(`../../server/uploads/${item.imageUrl}`)} /> 

but if you dont't add any initial values to item.imageUrl it will be undfeined and a error will be shone. so initially add value to item.imageUrl to a image at file system and replace that image URL with new image URL whenever you need to change the image.

sharun k k
  • 439
  • 8
  • 16
  • Ok i will try thanks. Can you explain me how add dynamic folder and photos in the src will work when i upload the app ? Its sounds weird (all the part with the static folder instead of regular route in nodejs – Roei Grinshpan Nov 30 '20 at 08:14
  • you have to configure according to what tech you are using. if you are using webpack then you can use wepack-image . when your are building app all these images will stored as static files, it is not recommended to store images in the app inself. instead store it in cloud as object is S3 or cloud buckets – sharun k k Nov 30 '20 at 08:52
  • So when i will deploy my app to google play i will need to change path everywhere? And get from the path that s3 give me? What i doing now ita only for temporarly checks? – Roei Grinshpan Nov 30 '20 at 12:42
  • i did this check {Object.keys(s).length === 0 ? null : ( )} and get the same error – Roei Grinshpan Nov 30 '20 at 12:51
  • https://stackoverflow.com/a/30868078/5990249 check this method – sharun k k Nov 30 '20 at 13:01