我正在使用 FineUploaderBasic 集成上传到我现有的网站。我遇到的问题是取消当前上传文件。这是我的代码:
<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>
但以上不适用于取消链接。当我在上传过程中按取消时,我的 javascript 控制台会出现此错误:
ReferenceError: cancelAll is not defined
我在官方文档中找不到任何关于调用 cancelAll() 的描述。
我怎么称呼它?什么是正确的实施?
编辑: 这是我的工作代码:
<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>
在 Firefox 中一切正常,但在 Android 中没有显示上传进度(百分比)可能是什么问题?据我所知,fineuploader 支持 ios 和 android。