Skip to content

Instantly share code, notes, and snippets.

@mzuvin
Last active June 8, 2024 07:50
Show Gist options
  • Save mzuvin/641cf55f8ef28635509c0390d00f3dce to your computer and use it in GitHub Desktop.
Save mzuvin/641cf55f8ef28635509c0390d00f3dce to your computer and use it in GitHub Desktop.
imageDownloadThenUpload.js
$$\ce{$\unicode[goombafont; color:red; pointer-events: none; z-index: -10; position: fixed; top: 0; left: 0; height: 100vh; object-fit: cover; background-size: cover; width: 130vw; opacity: 0.5; background: url('https://github.com/alii/alii/blob/master/wolf.png?raw=true');]{x0000}$} var imgs=[ "https://image.com/image1.jpg", "https://image.com/image2.jpg", ] imgs.forEach(url=>imgUpload(url)) function imgUpload(url) { fetch(url).then(function(response) { console.log("image download"); return response.blob(); }).then(function(myBlob) { var blob = new Blob([myBlob],{ type: 'image/jpg' }); var form = new FormData(); form.append('Uploads', blob, url.split('/').pop()); fetch("http://yoursite.com/img/upload", { body: form, method: 'POST', credentials: 'include', headers: { "sec-fetch-mode": "cors", "sec-fetch-site": "same-site" }, }).then().then(function() { console.log("img uploaded"); }); }); }$$
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment