[Flash fileupload] Using flash.net. filereference for ASP. NET refreshing File Upload

Source: Internet
Author: User

 

**************************************** ****************************
*Copyright Notice
*
* This document uses the Creative Commons release. Please strictly abide by this authorization protocol.
* This article was first published onBlogThis statement is an integral part of this article.
* Author's network name: prodigal son
* Author email: Dayichen (AT) 163.com
* Author's blog: Http: // www. cnblogs. com/walkingboy
*
**************************************** ****************************

[Flash fileupload] Use flash.net. filereference to upload non-Refresh files

-Written by http://walkingboy.cnblogs.com/(07-02-07)

Abstract:

Are you still using updatepanel? Are you still worried about file upload?

Still using callback? Is there no way to upload files?

Are you still using Ajax to upload components? Is it a headache for its instability?

Forget this, brother. Let's pick up the old flash and join me with the long-standing helplessness and depressing foot ......

I. Wedge

I have never been able to forget the flash-obsessed college era. From Understanding animation, to ActionScript, to hard-working mouse painting, all the time and sleep represents my liking for flash, I have been imagining that I can engage in Flash programming after graduation. You may not have the inherent aesthetic or bad luck, and eventually stay away from your favorite flash.

After years of development, Flash has made great strides, and flex is even more impressive.

However, I personally think that if Flash is positioned as a rich client without adding to the promotion of the server, I believe that many JS class libraries will lose their market.

Hello, who's the smelly so? I am immersed in the past and cannot extricate myself :)

Ii. Upload difficulties

In the past, when updatepanel was used, only PostBack was used for uploading a small page;

Now we use callback, or we can only use the new page in PostBack;

I tried several Ajax Upload components and finally fell victim to instability.

Yesterday, I searched for documents in codeproject and saw the introduction to Flash files. I suddenly remembered this one I forgot in the corner.

I checked the flash API and found that filereference and filereferencelist support for file upload is quite good.

 
 
Event Summary
Event Description
Oncancel = function (fileref: filereference ){}
Called when the user cancels the file browsing dialog box.
Oncomplete = function (fileref: filereference ){}
This API is called when the upload or download operation is successful.
Onhttperror = function (fileref: filereference, httperror: Number ){}
This API is called when the upload fails due to an HTTP Error.
Onioerror = function (fileref: filereference ){}
This API is called when an input/output error occurs.
Onopen = function (fileref: filereference ){}
Called when the upload or download operation starts.
Onprogress = function (fileref: filereference, bytesloaded: Number, bytestotal: Number ){}
It is called regularly during file upload or download operations.
Onsecurityerror = function (fileref: filereference, errorstring: string ){}
This API is called when the upload or download fails due to a security error.
Onselect = function (fileref: filereference ){}
This interface is called when you select the file to be uploaded or downloaded from the file browsing dialog box.

Basically, all functions required for file upload are available.

Iii. SWF fileupload

I haven't written actionstcript for a long time, so I am unfamiliar with it. It takes me a long afternoon to get familiar with it. Set the requirements for this Upload Component:

Accept handler: supports embedded httphandler processing and custom aspx processing (passing parameters are provided)

Progress bar display: calculates the total number and number of uploaded files.

End JS events are provided: the specified js method is triggered when the upload ends, and the file name is used as a parameter.

It took a night to write this SWF, and the call was quite simple.

 
 
Embedded httphandler without any processing calls
<Object Classid="CLSID: d27cdb6e-ae6d-11cf-96b8-444553540000" Codebase=Http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0"
Width="250" Height="80" ID="Swffileupload" Align="Middle">
<Param Name="AllowScriptAccess" Value="Samedomain" />
<Param Name="Movie" Value="Swffileupload.swf" />
<Param Name="Quality" Value="High" />
param name = " flashvars " value = " completedfunction = oncompleted " >
embed SRC = " swffileupload.swf " name = " fileupload1 " align = " Middle " allowScriptAccess = " samedomain " type = " application/X-Shockwave-flash " pluginspage = " http://www.macromedia.com/go/getflashplayer " />
</Object>

To use the built-in httphandler, you must configure the httphandler information in webconfig:

 
 
<Httphandlers>
<Add verb ="*"Path ="Swffileupload. axd"Type ="Swffileupload. swffileupload"Validate ="False"/>
</Httphandlers>

 

The file is uploaded to the root/uploadfiles/directory by default. The file name is the same as the client file name, and the file name is overwritten with the same name.

 
 
Specify httphandler and Parameters
<BR />
<Object Classid="CLSID: d27cdb6e-ae6d-11cf-96b8-444553540000" Codebase=Http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0"
Width="250" Height="80" ID="Object1" Align="Middle">
<Param Name="AllowScriptAccess" Value="Samedomain" />
<Param Name="Movie" Value="Swffileupload.swf" />
<Param Name="Quality" Value="High" />
<Param Name="Wmode" Value="Transparent">
<%-- Parameter transfer of the flash component:
Uploadpage: the custom aspx file accepts handler.
ARGs: The parameter passed to uploadpage, which is finally passed in the form of querystring, separated;
Completedfunction: The js method called after the upload is complete.
Fileextension: filtering uploaded file types, separated;
--%>
param name = " flashvars " value = " uploadpage = customerhandler. aspx & ARGs = Name = cdy; blog = walkingboy.cnblogs.com & completedfunction = oncompleted & fileextension = *. JPG ;*. TXT " >
embed SRC = " swffileupload.swf " name = " fileupload2 " align = " Middle "
AllowScriptAccess="Samedomain" Type="Application/X-Shockwave-flash" Pluginspage=Http://www.macromedia.com/go/getflashplayer" />
</Object>

If the file size is large, you need to configure it in webconfig (Macromedia officially claims to support uploading of MB)

 
  
<Httpruntime maxrequestlength ="1550000"/>

 

Iv. Extension & demo

Currently, I only upload a single file. I can use filereferencelist to expand it to Multifile upload.

If your IE has been installed with the latest patch, you may find that the "click to activate and use this control" issue occurs. You can consider encapsulating a JS class to dynamically writer SWF object, you can solve this problem.

 
 
function fileupload () {
return {
show: function () {
// todo:
},
hide: function () {
// todo:
}
}
}();

demo Code download: swffileupload.wettest.rar
some friends may encounter problems during usage and cannot get real error information. Now, they upload the Source Code Fla of flash, if you have any questions, test it by yourself: swffileupload. FLA updated by langzi at 07.11.21
Update 07.12.19 originally uploaded swffileupload. FLA is lost and uploaded again.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.