Flex frontend in ASP.NET MVC Upload.


/ Published in: MXML
Save to your folder(s)



Copy this code and paste it in your HTML
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
  3. xmlns:s="library://ns.adobe.com/flex/spark"
  4. xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600" creationComplete="OnCreationComplete(event)">
  5. <fx:Script>
  6. <![CDATA[
  7. import mx.events.FlexEvent;
  8. public var fileRef:FileReference = new FileReference();
  9.  
  10.  
  11. protected function OnCreationComplete(event:FlexEvent): void {
  12. fileRef.addEventListener(Event.SELECT, OnFileSeletected);
  13. fileRef.addEventListener(Event.COMPLETE, OnUploadComplete);
  14. }
  15.  
  16. public function OnFileSeletected(event:Event) : void {
  17. var request:URLRequest = new URLRequest("http://name-of-your-server/FlexChannel/VideoUpload");
  18. request.method = URLRequestMethod.POST;
  19. try{
  20. fileRef.upload(request);
  21. }
  22. catch(error:Error){
  23. trace(error.message);
  24. }
  25. }
  26.  
  27. public function OnUploadComplete(event:Event) : void{
  28. trace("complete");
  29. }
  30.  
  31.  
  32. public function OnOpenClicked(event:MouseEvent) : void{
  33. fileRef.browse([new FileFilter("Videos", "*.mov;*.avi;*.mp4;*.mpeg")]);
  34. }
  35.  
  36. ]]>
  37. </fx:Script>
  38. <fx:Declarations>
  39. <!-- Place non-visual elements (e.g., services, value objects) here -->
  40. </fx:Declarations>
  41. <s:Button label="Upload" click="OnOpenClicked(event)"/>
  42. </s:Application>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.