Tips for using Flex to upload files

Source: Internet
Author: User
Skills | upload

The tutorial is very simple, first look at the demo
http://kakera.35818.net/uploadsample/

Client, only 1 mxml, see note on the Ming
Uploadsample.mxml

Code Copy Box
<?xml version= "1.0" encoding= "Utf-8" ><mx:application xmlns:mx= "Http://www.adobe.com/2006/mxml" Vertical "verticalalign=" middle "horizontalalign=" center "><mx:style>global {fontsize:12;} </mx:style><mx:script><! [cdata[//first engage in a filereferenceprivate var file:filereference = new Filereference ()//upload status indicator, and the following text box binding [Bindable]private V Ar statetext:string = "Please select a file upload";//Createchildren earlier than the Creationcomplete event, the provincial registration event listening, directly written here protected override Functi On Createchildren (): void {super.createchildren (); File.addeventlistener (Event.select, file_select); File.addeventlistener (Event.complete, File_complete); File.addeventlistener (Progressevent.progress, file_progress );} Select Event Private Function File_select (e:event) for 1 files: void {statetext = "file selected" + File.name;} After uploading the event private function File_complete (e:event): void {statetext = "upload Complete";} Private Function File_progress (e:progressevent): void {statetext = "uploaded" + math.round (MB * e.bytesloaded/e.bytestotal) + "%";} First judge the file size, then upload, fileservice.aspx is the upload address private function upload (): void {if (file.size > 0) {statetext = "uploading" + fi Le.name;var request:urlrequest = new URLRequest ("fileservice.aspx"); File.upload (request);}]] ></mx:script><mx:panel width= "height=" 112 "layout=" vertical "title=" "Upload example" verticalalign= "Middle" horizontalalign= "center" ><mx:hbox><mx:textinput text= "{statetext}" width= "160" editable= "false"/> <mx:button label= "Browse" click= "File.browse ();" /></mx:hbox><mx:hbox><mx:button label= "Upload" click= "upload ();" /></mx:hbox></mx:panel></mx:application>
[Ctrl + a All select and copy]

Service side, using. NET production, look at the annotations to understand that
It doesn't matter if you don't understand the file is uploaded to the upload folder (to be created in advance), the filename is unchanged
Fileservice.aspx

Code Copy Box
<script language= "C #" runat= "server" >string Uploadfolder = "Upload"; Upload folder private void Page_Load (object sender, System.EventArgs e) {httpfilecollection files = request.files;if (files. Count = = 0) {Response.Write ("Do not access this file directly"); Response.End ();} String path = Server.MapPath (Uploadfolder),//Only 1th Httppostedfile file = files[0];if (file!= null && file. ContentLength > 0) {//flash will automatically send file name to request.form["filename"]string savepath = path + "/" + request.form["filename"] ; file. SaveAs (Savepath);} </script>
[Ctrl + a All select and copy]

Control upload time and file size depends on this.
Where maxRequestLength is the maximum upload file size, the unit is K, 4096 is allowed to upload 4M files, which is also the default value
Executiontimeout is the time to upload the file timeout, upload large files remember to set the larger
Web.config

Code Copy Box
<?xml version= "1.0" encoding= "Utf-8"? ><configuration><system.web><pttpruntime Maxrequestlength= "4096" executiontimeout= "10000"/></system.web></configuration>
[Ctrl + a All select and copy]

source file Download :demo.zip



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.