帮助我理解以下与AsyncFileUpload控件相关的javascript

时间:2021-07-04 03:10:32

in my current project I used a AsyncFileUpload control from AJAX Control Toolkits. After I got the async file upload part working, I needed to filter the file type so users can only upload image files. I found the following code off web and it worked well:

在我当前的项目中,我使用了AJAX控件工具包中的AsyncFileUpload控件。在异步文件上传部分工作后,我需要过滤文件类型,以便用户只能上传图像文件。我在web上找到了以下代码,它工作得很好:

function uploadStarted(sender, args) {  
        var filename = args.get_fileName();  
        var filext = filename.substring(filename.lastIndexOf(".") + 1);  
        if (filext == "jpg" || filext == "jpeg" || filext == "gif" || filext == "bmp")      {
            return true;
        }
        else 
        {  
            // force uploading cancel  
            args.set_cancel(true);  
            // set reason of cancel  
            args.set_errorMessage("Invalid File Format Selected");  
            return false;  
        }  
    } 

The problem is : I don't understand this javascript. What is the type of args parameter? Where are the methods such as "get_fileName()", "set_cancel()" defined? I went to the homepage of the AsyncFileUpload control but couldn't find any documentation regarding the "args".

问题是:我不理解这个javascript。args参数的类型是什么?“get_fileName()”等方法在哪里?”set_cancel()定义?我去了AsyncFileUpload控件的主页,但是找不到任何关于“args”的文档。

Can someone help me out explaining this Javascript? Thanks

有人能帮我解释一下这个Javascript吗?谢谢

1 个解决方案

#1


2  

I think I can answer my own question

我想我能回答我自己的问题。

The first parameter identifies the object that fired the event, while the second provides information on the file being uploaded. In fact, it contains five useful properties accessed using the get_abc() syntax demonstrated above.

第一个参数标识触发事件的对象,而第二个参数提供关于上传文件的信息。实际上,它包含使用上面演示的get_abc()语法访问的五个有用属性。

  • get_fileName() and get_path() both return the name of the file being uploaded
  • get_fileName()和get_path()都返回上传的文件的名称
  • get_length() returns the size of the file in bytes once uploaded. Returns null prior to upload
  • get_length()返回上传后文件的字节大小。在上载之前返回null
  • get_contentType() returns the mime type of the file once it is uploaded. Returns null prior to upload
  • get_contentType()在上传后返回文件的mime类型。在上载之前返回null
  • get_errorMessage() returns an error message should one occur. Returns null otherwise
  • get_errorMessage()返回一个错误消息。返回null,否则

For more details refer to this article:

有关更多细节,请参阅本文:

http://p2p.wrox.com/content/blogs/danm/enter-asyncfileupload-control

http://p2p.wrox.com/content/blogs/danm/enter-asyncfileupload-control

#1


2  

I think I can answer my own question

我想我能回答我自己的问题。

The first parameter identifies the object that fired the event, while the second provides information on the file being uploaded. In fact, it contains five useful properties accessed using the get_abc() syntax demonstrated above.

第一个参数标识触发事件的对象,而第二个参数提供关于上传文件的信息。实际上,它包含使用上面演示的get_abc()语法访问的五个有用属性。

  • get_fileName() and get_path() both return the name of the file being uploaded
  • get_fileName()和get_path()都返回上传的文件的名称
  • get_length() returns the size of the file in bytes once uploaded. Returns null prior to upload
  • get_length()返回上传后文件的字节大小。在上载之前返回null
  • get_contentType() returns the mime type of the file once it is uploaded. Returns null prior to upload
  • get_contentType()在上传后返回文件的mime类型。在上载之前返回null
  • get_errorMessage() returns an error message should one occur. Returns null otherwise
  • get_errorMessage()返回一个错误消息。返回null,否则

For more details refer to this article:

有关更多细节,请参阅本文:

http://p2p.wrox.com/content/blogs/danm/enter-asyncfileupload-control

http://p2p.wrox.com/content/blogs/danm/enter-asyncfileupload-control