Commit 0221ad74 authored by Oleg Dzhimiev's avatar Oleg Dzhimiev

1. fixed for chrome for images bigger than 2MB (dumped readAsDataURL()) 2. for...

1. fixed for chrome for images bigger than 2MB (dumped readAsDataURL()) 2. for synced - restore trigger only after images are downloaded
parent a2f1896a
var tp_old = 0; var tp_old = 0;
var DLC = 0;
function take_snapshot(){ function take_snapshot(){
...@@ -43,18 +44,11 @@ function trigger(){ ...@@ -43,18 +44,11 @@ function trigger(){
function download_all(rtp){ function download_all(rtp){
DLC = 0;
ports.forEach(function(c,i){ ports.forEach(function(c,i){
download_single(ip+":"+c+"/img"); download_single(ip+":"+c+"/timestamp_name/img");
}); });
if (rtp) {
setTimeout(function(){
read_tp();
},200);
}else{
$("#snapshot").attr("disabled",false);
}
} }
function download_single(addr){ function download_single(addr){
...@@ -66,6 +60,7 @@ function download_single(addr){ ...@@ -66,6 +60,7 @@ function download_single(addr){
http.onload = function(e){ http.onload = function(e){
if (this.status === 200) { if (this.status === 200) {
// To access the header, had to add // To access the header, had to add
// printf("Access-Control-Expose-Headers: Content-Disposition\r\n"); // printf("Access-Control-Expose-Headers: Content-Disposition\r\n");
// to imgsrv // to imgsrv
...@@ -73,34 +68,28 @@ function download_single(addr){ ...@@ -73,34 +68,28 @@ function download_single(addr){
pass_to_file_reader(filename,http.response); pass_to_file_reader(filename,http.response);
DLC++;
if (DLC==ports.length){
if ($("#synced").prop("checked")) {
read_tp();
}else{
$("#snapshot").attr("disabled",false);
}
}
} }
} }
http.send(); http.send();
/*
return 0;
var link = document.createElement('a');
link.setAttribute('download', null);
link.style.display = 'none';
link.download = addr;
link.href = addr;
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
*/
} }
// from here: // from here:
// https://diegolamonica.info/multiple-files-download-on-single-link-click/ // https://diegolamonica.info/multiple-files-download-on-single-link-click/
// http://jsfiddle.net/diegolamonica/ssk8z9pa/ // http://jsfiddle.net/diegolamonica/ssk8z9pa/
function pass_to_file_reader(filename,filedata){ // (helped a lot) https://stackoverflow.com/questions/19327749/javascript-blob-filename-without-link
function pass_to_file_reader(filename,fileblob){
var parameters = filename.split(";"); var parameters = filename.split(";");
for (var i=0;i<parameters.length;i++) parameters[i]=parameters[i].split("="); for (var i=0;i<parameters.length;i++) parameters[i]=parameters[i].split("=");
...@@ -111,27 +100,61 @@ function pass_to_file_reader(filename,filedata){ ...@@ -111,27 +100,61 @@ function pass_to_file_reader(filename,filedata){
} }
} }
var url = window.URL.createObjectURL(fileblob);
var a = $('<a>')
.attr('href', url)
.attr('download',filename)
// Firefox does not fire click if the link is outside
// the DOM
.appendTo('body');
a[0].click();
//a.click();
// delay?
setTimeout(function(){
a.remove();
},200);
//return;
// The code below will not work because .readAsDataURL() is limited in Chrome to 2MB, but no limit in FF.
/*
var reader = new FileReader(); var reader = new FileReader();
reader.filename = filename; reader.filename = filename;
reader.onloadend = function(e){ reader.onloadend = function(e){
//console.log("Load ended!");
var file = [this.filename,e.target.result]; var file = [this.filename,e.target.result];
var theAnchor = $('<a />') var theAnchor = $('<a>')
.attr('href', file[1]) .attr('href', file[1])
.attr('download',file[0]) .attr('download',file[0])
// Firefox does not fires click if the link is outside // Firefox does not fire click if the link is outside
// the DOM // the DOM
.appendTo('body'); .appendTo('body');
theAnchor[0].click(); theAnchor[0].click();
//theAnchor.click(); //theAnchor.click();
//delay
setTimeout(function(){
theAnchor.remove(); theAnchor.remove();
},200);
}; };
reader.onload = function(e){
//console.log("onload");
};
reader.readAsDataURL(filedata); reader.readAsDataURL(filedata);
*/
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment