Once we've successfully received our blob, we pass it into our showProduct() function, which displays it. Then we call response.blob to return a promise with the image blob object. You're right, this approach can only get the file with the relative path. headers: { // the content type header value is usually auto-set . Thanks for your reply. Thanks for keeping DEV Community safe. To learn how to fetch data from the server and use it to update the Did you mean to use. What is the purpose of this D-shaped ring at the base of the tongue on my hiking boots? Here's the full list of all possible fetch options with their default values (alternatives in comments): let promise = fetch( url, { method: "GET", // POST, PUT, DELETE, etc. You'll rarely have to do this, so we'll just concentrate on the first one for now. I spend hours to final. Premium CPU-Optimized Droplets are now available. How can I access the image file url now? The fetch () method returns a Promise which then can be chained with then () and catch () for better error handling. It has a number of advantages, and what is really nice about it is that browsers have recently added the ability to consume a fetch response as a readable stream. Where does this (supposedly) Gibson quote come from? How to prevent buttons from submitting forms, Get selected text from a drop-down list (select box) using jQuery, How to redirect one HTML page to another on load. The Request.body and Response.body properties are available, which are getters exposing the body contents as a readable stream. I can access and see image file on http://192.168.22.124:3000/source/592018124023PM-pexels-photo.jpg. To fetch a user we need: fetch('https://api.github.com/users/USERNAME'). It also provides a global fetch() method that provides an easy, logical way to fetch resources asynchronously across the network. Site design / logo 2023 Stack Exchange Inc; user contributions licensed under CC BY-SA. Fetch - JavaScript Uncaught (in promise) SyntaxError: Unexpected token in JSON at position 0. Create an async function getUsers(names), that gets an array of GitHub logins, fetches the users from GitHub and returns an array of GitHub users. Always undefined when done is true. Its more difficult. In this example, we will fetch a different verse of the poem (which you may well recognize) when it's selected in the drop-down menu. If there is no more stream to read, you return out of the function. If done is not true, we process the new chunk we've read (contained in the value property of the results object) and then call the pump() function again to read the next chunk. I have been creating a scraper and need an automation to download some images. When the server provides them, the JavaScript can use the data to update the page, typically by using DOM manipulation APIs. So because fetch() returns a promise, we pass a function into the then() method of the returned promise. Or you can request a resource under an online server, such as some image sharing websites, or you can use base64 format data resources. How do I remove a property from a JavaScript object? I get this on console log: 192.168.22.124:3000/source/[object Blob]. The data requested is often JSON, which is a good format for transferring structured data, but can also be HTML or just text. According to MDN, Fetch is described as below: The Fetch API provides a JavaScript interface for accessing and manipulating parts of the HTTP pipeline, such as requests and responses. IT does not show such information other than list of files. The numbers in the table specify the first browser versions that fully support Fetch API: The example below fetches a file and displays the content: Since Fetch is based on async and await, the example above might be easier to understand like this: Or even better: Use understandable names instead of x and y: Get certifiedby completinga course today! Of course it all depends on your requirements. @CertainPerformance Using blob I get this on console log: Did you read the section in the link I posted? Just inside the