Uppload Save Locally
by Anand Chowdhary
HTML
<script src="https://unpkg.com/uppload/dist/uppload.polyfills.js"></script>
<div class="row">
<img class="urlImage1" style="height: 100px;width: auto;"><br>
<input type="text" class="urlImage1" /><br>
<button class="uploadImage1">Upload image</button>
</div>
JavaScript 1.7
/* https://stackoverflow.com/a/36899900/1656944 */
function saveFile (name, type, data) {
if (data != null && navigator.msSaveBlob)
return navigator.msSaveBlob(new Blob([data], { type: type }), name);
var a = $("<a style='display: none;'/>");
var url = window.URL.createObjectURL(new Blob([data], {type: type}));
a.attr("href", url);
a.attr("download", name);
$("body").append(a);
a[0].click();
window.URL.revokeObjectURL(url);
a.remove();
}
const profilePicture1 = new Uppload({
value: "https://randomuser.me/api/portraits/men/1.jpg",
bind: [".urlImage1"],
call: [".uploadImage1"],
allowedTypes: "image",
endpoint: "/docs",
uploadFunction: function(file, metadata) {
return new Promise(function (resolve, reject) {
console.log("Saving file", file);
saveFile("uploaded-image.png", "image/png", file);
// For the file preview, you should resolve a URL below; even data URL works:
resolve();
});
}
});