• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

File uploading in flex

aman thind
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have an mxml which i have taken from some website

<?xml version="1.0" encoding="utf-8"?>
<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" width="100%" height="100%" fontSize="12" creationComplete="init()">
private var fileRef:FileReference;

private const FILE_UPLOAD_URL:String = "http://www.YOUR-WEBSITE-HERE.com/fileref/uploader.cfm";

private function init():void {
fileRef = new FileReference();
fileRef.addEventListener(Event.SELECT, fileRef_select);
fileRef.addEventListener(ProgressEvent.PROGRESS, fileRef_progress);
fileRef.addEventListener(Event.COMPLETE, fileRef_complete);

private function browseAndUpload():void {
message.text = "";

private function fileRef_select(evt:Event):void {
try {
message.text = "size (bytes): " + numberFormatter.format(fileRef.size);
fileRef.upload(new URLRequest(FILE_UPLOAD_URL));
} catch (err:Error) {
message.text = "ERROR: zero-byte file";

private function fileRef_progress(evt:ProgressEvent):void {
progressBar.visible = true;

private function fileRef_complete(evt:Event):void {
message.text += " (complete)";
progressBar.visible = false;

<mx:NumberFormatter id="numberFormatter" />

<mx:Button label="Upload file"
click="browseAndUpload();" />
<mx:Label id="message" />
<mx:ProgressBar id="progressBar"
visible="false" />

I need to upload a file and call a webservice method and save this file in database. But i am totally new to Flex and don't have a single clue how to achieve this? Can anyone guide me how to achieve this. What should i pass as URL if i need to just save in database?
Paul Sturrock
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should pass the URL of the server side code you have written to process the uploaded file.

Personally, rather than guessing your way round this code I'd stop what you are doing and take a few days to learn about the basics of Flex. It will be much less painful in the long run.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic