Skip to content

Instantly share code, notes, and snippets.

@mzuvin
Created December 3, 2021 19:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • 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
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