Skip to content

Commit

Permalink
Merge pull request #93 from AidasK/master
Browse files Browse the repository at this point in the history
Fix for support param and cancel function, and total chunks parameter added
  • Loading branch information
steffentchr committed Aug 11, 2013
2 parents c3e7f27 + aa0c831 commit 6e8be08
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 9 deletions.
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -44,6 +44,7 @@ Most of the magic for Resumable.js happens in the user's browser, but files stil
To handle the state of upload chunks, a number of extra parameters are sent along with all requests:

* `resumableChunkNumber`: The index of the chunk in the current upload. First chunk is `1` (no base-0 counting here).
* `resumableTotalChunks`: The total number of chunks.
* `resumableChunkSize`: The general chunk size. Using this value and `resumableTotalSize` you can calculate the total number of chunks. Please note that the size of the data received in the HTTP might be lower than `resumableChunkSize` of this for the last chunk for a file.
* `resumableTotalSize`: The total file size.
* `resumableIdentifier`: A unique identifier for the file contained in the request.
Expand Down
11 changes: 6 additions & 5 deletions resumable.js
Expand Up @@ -25,7 +25,7 @@ var Resumable = function(opts){
&&
(typeof(FileList)!=='undefined')
&&
(!!Blob.prototype.webkitSlice||!!Blob.prototype.mozSlice||Blob.prototype.slice||false)
(!!Blob.prototype.webkitSlice||!!Blob.prototype.mozSlice||!!Blob.prototype.slice||false)
);
if(!this.support) return(false);

Expand Down Expand Up @@ -462,7 +462,8 @@ var Resumable = function(opts){
resumableTotalSize: $.fileObjSize,
resumableIdentifier: $.fileObj.uniqueIdentifier,
resumableFilename: $.fileObj.fileName,
resumableRelativePath: $.fileObj.relativePath
resumableRelativePath: $.fileObj.relativePath,
resumableTotalChunks: $.fileObj.chunks.length
};
// Mix in custom data
var customQuery = $.getOpt('query');
Expand Down Expand Up @@ -692,9 +693,9 @@ var Resumable = function(opts){
$.fire('pause');
};
$.cancel = function(){
$h.each($.files, function(file){
file.cancel();
});
for(var i = $.files.length - 1; i >= 0; i--) {
$.files[i].cancel();
}
$.fire('cancel');
};
$.progress = function(){
Expand Down
9 changes: 6 additions & 3 deletions samples/Node.js/app.js
Expand Up @@ -43,8 +43,11 @@ app.get('/upload', function(req, res){

app.get('/download/:identifier', function(req, res){
resumable.write(req.params.identifier, res);


});
});
app.get('/resumable.js', function (req, res) {
var fs = require('fs');
res.setHeader("content-type", "application/javascript");
fs.createReadStream("../../resumable.js").pipe(res);
});

app.listen(3000);
Binary file added samples/Node.js/public/cancel.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 10 additions & 1 deletion samples/Node.js/public/index.html
Expand Up @@ -19,7 +19,7 @@ <h1>Resumable.js</h1>

<h3>Demo</h3>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script src="https://raw.github.com/23/resumable.js/master/resumable.js"></script>
<script src="resumable.js"></script>

<div class="resumable-error">
Your browser, unfortunately, is not supported by Resumable.js. The library requires support for <a href="http://www.w3.org/TR/FileAPI/">the HTML5 File API</a> along with <a href="http://www.w3.org/TR/FileAPI/#normalization-of-params">file slicing</a>.
Expand All @@ -37,6 +37,7 @@ <h3>Demo</h3>
<td class="progress-pause" nowrap="nowrap">
<a href="#" onclick="r.upload(); return(false);" class="progress-resume-link"><img src="resume.png" title="Resume upload" /></a>
<a href="#" onclick="r.pause(); return(false);" class="progress-pause-link"><img src="pause.png" title="Pause upload" /></a>
<a href="#" onclick="r.cancel(); return(false);" class="progress-cancel-link"><img src="cancel.png" title="Cancel upload" /></a>
</td>
</tr>
</table>
Expand Down Expand Up @@ -96,6 +97,14 @@ <h3>Demo</h3>
$('.resumable-file-'+file.uniqueIdentifier+' .resumable-file-progress').html(Math.floor(file.progress()*100) + '%');
$('.progress-bar').css({width:Math.floor(r.progress()*100) + '%'});
});
r.on('cancel', function(){
$('.resumable-file-progress').html('canceled');
});
r.on('uploadStart', function(){
// Show pause, hide resume
$('.resumable-progress .progress-resume-link').hide();
$('.resumable-progress .progress-pause-link').show();
});
}
</script>

Expand Down

0 comments on commit 6e8be08

Please sign in to comment.