add chunk upload files
This commit is contained in:
parent
59114ed01d
commit
e6c5194edd
4 changed files with 274 additions and 1 deletions
63
static/js/upload.js
Normal file
63
static/js/upload.js
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
// vi:si:et:sw=4:sts=4:ts=4
|
||||
$(document).ready(function() {
|
||||
function formatSize(bytes) {
|
||||
var base = 1000,
|
||||
PREFIXES = ['K', 'M', 'G', 'T', 'P'],
|
||||
len = PREFIXES.length,
|
||||
val,
|
||||
pow = 1;
|
||||
while(Math.pow(base, pow+1) < bytes) {
|
||||
pow += 1;
|
||||
}
|
||||
return (Math.round(100* bytes / Math.pow(base, pow)) / 100) + ' ' + PREFIXES[pow-1] + 'B';
|
||||
}
|
||||
|
||||
$('#file').val('');
|
||||
$('#file').change(function(e) {
|
||||
if(this.files.length>0) {
|
||||
$('#file').hide();
|
||||
$('#upload').show();
|
||||
$('#status').width(400);
|
||||
$('#status').html('' + this.files[0].name + ' (' + formatSize(this.files[0].size) + ')');
|
||||
} else {
|
||||
$('#upload').hide();
|
||||
}
|
||||
$('#upload').click(function(e) {
|
||||
e.stopPropagation();
|
||||
var file = $('#file')[0].files[0];
|
||||
|
||||
$('#upload').hide();
|
||||
$('#status').width(200);
|
||||
$('#status').css('background-color', '#eee');
|
||||
$('#status').html('<div id="progress" style="background-color: #666;height:20px;width:0%" /><div id="progressstatus" style="background-color: #fff;">uploading</div>');
|
||||
ChunkUploader({
|
||||
file: file,
|
||||
url: '/add',
|
||||
data: {
|
||||
'firefogg': 1,
|
||||
'name': file.name
|
||||
},
|
||||
progress: function(data) {
|
||||
var progress = data.progress
|
||||
$('#progress').css('width', parseInt(progress*100, 10) +'%');
|
||||
$('#progressstatus').html(parseInt(progress*100, 10) + '% - ' + data.status);
|
||||
},
|
||||
callback: function(result) {
|
||||
if(result.progress == 1) {
|
||||
var response = JSON.parse(result.responseText);
|
||||
if(response.resultUrl) {
|
||||
document.location.href = response.resultUrl;
|
||||
} else {
|
||||
$('#status').html(response.status);
|
||||
}
|
||||
} else {
|
||||
$('#status').width(500);
|
||||
$('#status').css('background-color', '#fff');
|
||||
$('#status').html(result.status);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue