Mit*_*hir 4 javascript asp.net ajax asyncfileupload
我正在使用AsyncFileUpload以允许用户异步上传文件.
我想将文件的大小限制为1MB.
到目前为止,我看到的只能在上传完成时得到文件的长度
比如上传开始时:
(OnClientUploadStarted)
function UploadStarted(sender,args) 
{
   //if bigger than 1MB (approximately)
   if (args.get_length() > 1000000 ) 
   {
       ShowActionNotificationError( errorMessage); 
       return false;  
    }
}
args.get_length()为null,所以我不能使用它...
上传完成后:
(OnClientUploadComplete)
function UploadComplete(sender,args) 
{
    //if bigger than 1MB (approximately)
    if (args.get_length() > 1000000 ) 
    {
        ShowActionNotificationError( errorMessage); 
        return false;  
    }
}
工作正常,但文件已经上传...
那么在上传之前如何知道文件的大小呢?我错过了一些非常简单的事吗?
我真的想在不处理HTTP请求长度和排序的情况下这样做.
谢谢!
小智 6
您可以在客户端上传开始事件中执行此操作。
if (sender._inputFile.files[0].size >= maxFileSize) {
    sender._stopLoad();
}
_stopLoad 将调用您的上传错误事件。
经过一些实质性的研究后,我意识到使用AJAX无法做到这一点.
当我浏览雅虎邮件和Gmail这样的网站时,它是由Flash完成的.
在Hotmail中,它完成了Silverlight.
有一个名为Uploadify的免费(现在)Flash上传控件...
我现在正致力于整合它.
如果我错了请纠正我!:)
| 归档时间: | 
 | 
| 查看次数: | 8461 次 | 
| 最近记录: |