I am using FineUploaderBasic to integrate uploading to my existing web site. The problem I have is with cancelling current uploading file. This is my code:
<div id="button" class="btn btn-large btn-primary">
<i class="icon-upload icon-white"></i>
Upload
<i class="icon-upload icon-white"></i>
</div>
<a href="#" id="cancelling">cancel</a>
<div id="uploader"></div>
<script>
window.onload = function () {
var uploader = new qq.FineUploaderBasic({
debug: true,
element: document.getElementById('uploader'),
button: document.getElementById('button'),
request: {
endpoint: 'upload'
},
multiple: false,
maxConnections: 1,
allowedExtensions: ['jpeg', 'jpg', 'gif', 'png', 'jpe',
'mp3', 'wma', 'wav',
'mp4', 'flv', '3gpp', 'webm',
'zip', 'rar', 'gz', 'tar', 'tgz', 'iso'
],
callbacks: {
onSubmit: function (id, fileName) {},
onUpload: function (id, fileName) {},
onProgress: function (id, fileName, loaded, total) {
$('#cancelling').click(function () {
cancelAll();
});
},
onComplete: function (id, fileName, responseJSON) {},
onError: function (id, name, reason, xhr) {},
onCancel: function (id, fileName) {
alert('cancelled');
}
}
});
}
</script>
But above does not work for cancel link. When I press cancel while progressing upload, my javascript console gives this error:
ReferenceError: cancelAll is not defined
I could not find any descriptions of calling cancelAll() in official documentation.
How can I call it? What is the right implementation?
Edit: This is my working code:
<div id="uploader">
<div id="button" class="btn btn-large btn-primary">
<i class="icon-upload icon-white"></i>
Загрузить файл
<i class="icon-upload icon-white"></i>
</div>
<h4><div id="progress" class="hide"></div></h4>
<a id="cancel_link" href="#" class="hide"><h4>Cancel uploading</h4></a>
</div>
<script>
window.onload = function()
{
var uploader = new qq.FineUploaderBasic
({
element: document.getElementById('uploader'),
button: document.getElementById('button'),
request:
{
endpoint: 'upload'
},
multiple: false,
maxConnections: 1,
validation:
{
allowedExtensions: ['jpeg', 'jpg', 'gif', 'png', 'jpe',
'mp3', 'wma', 'wav',
'mp4', 'flv', '3gpp', 'webm',
'zip', 'rar', 'gz', 'tar', 'tgz'],
sizeLimit: 20971520 // 20 MB = 20 * 1024 * 1024 bytes
},
messages:
{
sizeError: 'Error: {sizeLimit}',
typeError: '{file} error. valid: {extensions}.'
},
callbacks:
{
onSubmitted: function(id, fileName)
{
$('#cancel_link').show();
$('#button').hide();
$('#progress').show();
$('#progress').html('Submitted...');
var cancel_btn = document.getElementById('cancel_link');
var self = this;
qq(cancel_btn).attach('click', function(){
self.cancel(id);
});
},
onProgress: function(id, fileName, loaded, total)
{
if(loaded<total)
{
progress = '"' + fileName + '" загружено ' + Math.round(loaded / total*100) +'%';
$('#progress').html(progress);
}
else
{
$('#progress').html('Подождите...');
}
},
onComplete: function(id, fileName, responseJSON)
{
$('#cancel_link').hide();
if(responseJSON.success)
{
$('#progress').html('Подождите...');
window.location.replace(responseJSON.url);
}
},
onError: function(id, name, reason, xhr)
{
$('#cancel_link').hide();
$('#progress').hide();
$('#button').show();
alert(reason);
},
onCancel: function(id, fileName)
{
$('#cancel_link').hide();
$('#progress').hide();
$('#button').show();
}
}
});
}
</script>
Everything works in Firefox, but progress of uploading (percents) does not show in Android what can be problem? As far as I know fineuploader support ios and android.