How to locally save the external images from an API?
See original GitHub issueI’m doing some research and making some demo using react-static.
I found a problem with the images, which is external images from the API instead of the images in CSS or local image for the UI.
For example, I’ve developed an API with Wordpress basic, there’re a lot of posts are returned by that API, sometimes there are a lot of images are returned as “Array” like the following JSON.
{
"title": "testing title...",
"content": "testing content...",
"images": [
"http://testing.abc.com/images/upload/testing1.jpg",
"http://testing.abc.com/images/upload/testing2.jpg",
"http://testing.abc.com/images/upload/testing3.jpg"
]
}
Is there any way to download the image and put them into the the <img tag as a relative path instead of absolute path, when we build a static website. So the result should be …
<img src="./public/images/upload/testing1.jpg"/>
or (based on the page url route)
<img src="../../public/images/upload/testing1.jpg"/>
instead of
<img src="http://testing.abc.com/images/upload/testing1.jpg"/>
Issue Analytics
- State:
- Created 4 years ago
- Comments:6
Top Results From Across the Web
Save an image to localStorage – JavaScript Tutorial - YouTube
Source code: https://openjavascript.info/2022/10/11/how-to- save -and-retrieve- images -from-localstorage/⚡ Looking for high-performance, ...
Read more >Saving images on an external server - Stack Overflow
Create a WebAPI (REST API) on the 2nd server you want images to be saved on. Send the images in Base64EncodedString to the...
Read more >8 - Save and set an external link image programatically
I'm wondering how do Drupal save the image from an external link. I use the following code. $imageUri = 'https://api.statvoo.com/favicon/?url= ...
Read more >Saving an Image from URL in PHP - GeeksforGeeks
It's easy to go to the page and use right click button and save the image. But what if you wanted to do...
Read more >Programmatically Uploading Images, Videos, and Other Files
Learn how to upload images, videos, and other files with only a line or two of code - with cloud storage, CDN delivery,...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Right… so thinking a bit on how you could do this flow in your static config.
images/file1.jpg
as a prop to the posts route.This process is a genuine candidate to be implemented in a plugin, related to #1130 issue, maybe a component that automatically download images in a static directory depending of they use. Or an official guide to use webpack + React Static to do this with an api.