File Upload in Flex

3 views
Skip to first unread message

Saurabh

unread,
Dec 28, 2009, 2:55:30 AM12/28/09
to Flex India Community
Hi,
I want to do a file upload in my flex application.
I know there is FileReference class which allows me to browse to a
file and then using Upload method I can upload the file.
But the problem is that, I have a absolute path of a file which I want
to upload, I don't want to show the browse control to the user to
select the file and then go for upload. I have the path of the file
and want to use that path only to do the upload.

How can I skip the FileRefrence's browse and specify the absolute
path? I tried name property but its read only.

I don't want to do this in my flex web application and not in AIR.

Any ideas?

Saurabh Surana

unread,
Dec 29, 2009, 2:59:58 AM12/29/09
to flex_...@googlegroups.com
Regards,
Saurabh

Kikka

unread,
Dec 29, 2009, 1:43:30 PM12/29/09
to Flex India Community
HI.. have u uploaded file before in Flex. if yes then you know how the
file upload works . usually after selecting the file u'll be calling
the fileref's upload method where u'll be passing a request object. in
that request object u create a parameter and put the absolute path of
the file which u want to upload instead of using flex upload directly
read the file frm the location

Saurabh Surana

unread,
Dec 31, 2009, 1:24:50 AM12/31/09
to venkatak...@gmail.com, flex_...@googlegroups.com
Hi,
Thanks for the reply.
I am not an expert in this, but what I understood is you are asking me to add one more variable to the URLVariables object which I assign to URLRequest's Data property. Can you tell me what should be the name of the variable to which I will assign the absolute path? And also I didn't understood this line from your post "... to upload instead of using flex upload directly read the file frm the location", if I don't use flex's upload directly then how to the upload otherwise?

I have following code which I am using for doing the upload
========================
var fileUpload:FileReference = new FileReference()
var request:URLRequest = new URLRequest("mywebserver/datafolder");
               
var variables:URLVariables = new URLVariables();
variables.op = "fileupload";
variables.proc="sync";
               
variables.username = "username";
request.data = variables;
                  
try
{
    fileUpload.upload(request);
}
catch(error:Error)
{
    //log the error
}
========================

I am using appropriate event handlers, but to simplify the post I removed it from here.

So in this code how do I tell that use the file from a absolute path, lets say I have a variable _filePath which stores the path from which I have to upload the file.

Regards,
Saurabh


--

You received this message because you are subscribed to the Google Groups "Flex India Community" group.
To post to this group, send email to flex_...@googlegroups.com.
To unsubscribe from this group, send email to flex_india+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/flex_india?hl=en.



ravi kanth

unread,
Jan 17, 2010, 3:03:06 AM1/17/10
to flex_...@googlegroups.com
@Saurabh: Can you share complete code, So that i can easily get, how to upload the file and how it works?

Hari Narayanan

unread,
Jan 18, 2010, 1:52:08 AM1/18/10
to Flex India Community
Hi Friends,

How can we set the folder path' we want to upload from flex? I
wrote an uploadhandler in asp. My upload handler is following.
<%@ WebHandler Language="C#" Class="FileUploadHandler" %>

using System;
using System.Web;

public class FileUploadHandler : IHttpHandler {

public void ProcessRequest (HttpContext context)
{
string applicationPath = context.Server.MapPath
(context.Request.ApplicationPath);
string folderPath = applicationPath + "/Uploads/";
string filePath = string.Empty;

System.IO.DirectoryInfo objDirectory = new
System.IO.DirectoryInfo(folderPath);

// if the directory does not exists, create it.
if (!objDirectory.Exists)
{
objDirectory.Create();
}

string result = "OK";
context.Response.ContentType = "text/plain";
if (context.Request.Files.Count > 0)
{
HttpPostedFile file = context.Request.Files[0];
try
{
filePath = folderPath + file.FileName;
file.SaveAs(filePath);
}
catch (Exception ex)
{
result = "File Upload Failed. Exception : " +
ex.Message;
}
}
else
{
result = "No File Uploaded";
}
context.Response.Write(result);
}

public bool IsReusable
{
get
{
return false;
}
}

}

Pls help me.. It is urgent...

Regards,
Hari

Reply all
Reply to author
Forward
0 new messages