Created
December 3, 2021 19:49
-
-
Save mzuvin/641cf55f8ef28635509c0390d00f3dce to your computer and use it in GitHub Desktop.
imageDownloadThenUpload.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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