0

Suppose we have an <img src='http://example.net/image.png' /> that has been loaded and is displayed by the browser. How can we PUT that PNG file to, say, http://example.net/image2.png, preferably without first GETting it again?

My attempt:

fetch('http://www.example.net', {
    method: 'PUT',
    headers: {
      'Content-Type': 'image/png'
    },
    body: // What to put here?
}
Museful
  • 6,711
  • 5
  • 42
  • 68
  • So you don't have the image file itself? I don't think you can send a file without the file. – Sparlarva Jan 25 '19 at 18:27
  • @Sparlarva Well the browser must have it. – Museful Jan 25 '19 at 18:27
  • What's your case? Do you want to get an image without having to request it twice? It already may be in browser cache, so there will be no request to the server. If you want to make sure it's cached, use service workers. – Estus Flask Jan 25 '19 at 18:35
  • @estus That's what I'm going with for now (re-request the image from the same URL) but the application requires that this resource not be cached as it may change at any time. If it does change, I would need to PUT the one in the browser (to the server), not the one on the server (to the server). – Museful Jan 25 '19 at 18:48
  • If it can change over time, you could use queries to control caching, /image.png?timestamp=... . And as I said, it seems like a case for service worker. – Estus Flask Jan 25 '19 at 19:13

0 Answers0