I everyone, I'm new here.
I'm tring to implement plupload with the ability to resume upload after a lost/fount connection.
The upload actualy resume correctly but the plupload state dosen't change accordingly.
The percentage increase but there is non overall bar and the buttons "add files" and "start upload" are shown.
Thanks in advace and sorry for my bad bad english.
Here's the code:
var uploader;
var upload = {
file: null,
offset: 0
}
// Convert divs to queue widgets when the DOM is ready
$(document).ready(function(){
uploader = $("#uploader").plupload({
// General settings
runtimes : 'html5,browserplus,gears,flash,silverlight',
url : 'upload_script.php?targetdir='+actualFolder,
chunk_size : '1mb',
unique_names : false,
max_retries: 5
// Views to activate
views: {
list: true,
thumbs: true, // Show thumbs
active: 'thumbs'
},
// Flash settings
flash_swf_url : '../js/plupload/Moxie.swf',
// Silverlight settings
silverlight_xap_url : '../js/plupload/Moxie.xap',
preinit: attachCallbacks // attach callbacks before queue
});
});
function retry(Up) {
console.log('[plupload] restarted (retry)');
upload.file.loaded = upload.offset;
upload.file.status = plupload.UPLOADING;
// the following is similar to uploader.start()
// but starts a specific file at a specific position
Up.state = plupload.STARTED;
$('.plupload_header_content').html(header_content);
Up.trigger('UploadFile', upload.file);
Up.start();
};
// attach callbacks for FileUploaded and Error
function attachCallbacks(Uploader) {
Uploader.bind('UploadComplete', function(Up, Files) {
var length = Files.length;
//console.log(length);
var file_list='';
for (var i = 0; i < length; i++) {
file_list = file_list+Files[i]['name']+',';
}
});
var allowrew='n';
Uploader.bind('BeforeUpload', function(Up, File) {
upload.file = File;
upload.offset = 0;
window.addEventListener("offline", function () {
console.log('[plupload] stopped (offline)');
Uploader.stop();
}, false);
window.addEventListener("online", function () {
console.log('[plupload] restarted (online)');
if(upload.file === null) {
return false;
}
retry(Uploader);
}, false);
$.ajax({
type: "GET",
url: "checkFimeName.php",
data: "f="+File.name+"&targetdir="+actualFolder,
success: function(response){
if(response=='si' && allowrew=='n'){
Uploader.stop();
var answer = confirm("Il file "+File.name+" esiste già. Sovrascriverlo?")
if (answer){
allowrew='s';
Uploader.start();
}else{
Uploader.removeFile(File);
Uploader.start();
if(Uploader.total.queued == 0) {
}
}
};
}
});
});
Uploader.bind('ChunkUploaded', function(up, file, info) {
upload.offset = info.offset;
});
Uploader.bind('FileUploaded', function(Up, File) {
allowrew='n';
upload.file = null;
});
Uploader.bind('Error', function(up, error) {
console.log(error.code)
console.log(plupload.HTTP_ERROR)
if(error.code !== plupload.HTTP_ERROR) {
return true;
}
uploader.stop();
console.warn('[plupload] stopped (HTTP Error)');
window.setTimeout(function(){retry(up)}, 5000);
return false
});
}