9 Replies Latest reply on Mar 13, 2011 4:06 AM by Maria Pieroszkiewicz

    Upload files

    athiroy

      hi

      i want to upload file using flex 4. if any idea pls suggest me.

       

      regards

      athi

        • 1. Re: Upload files
          Matt Le Fevre Level 4

          you'll have to use a FileReference()

           

          http://livedocs.adobe.com/flex/3/langref/flash/net/FileReference.html

           

          unless you want to upload multiple files at a time, in which case you'll need to use a FileReferenceList()

           

           

          and you'll need a server-side script to handle the uploaded data.

          • 2. Re: Upload files
            athiroy Level 1

            hi

                  i folowed this url http://livedocs.adobe.com/flex/3/langref/flash/net/FileReference.html

              but i don't know why the cfm is in the following line

              uploadURL.url = "http://www.[yourDomain].com/yourUploadHandlerScript.cfm";

            could u explain me

            regards

            athi

            • 3. Re: Upload files
              Matt Le Fevre Level 4

              It's a coldfusion script, it handles the POST'd file data from the application.

               

              Flash player cannot directly upload files, so it just references file information to a script, which then handles the uploading.

               

              your upload script doesn't necessarily have to be coldfusion, it could be php or even asp i believe.

               

               

               

              an example of PHP handling POST'd file information can be found here

               

              http://www.w3schools.com/PHP/php_file_upload.asp

              • 4. Re: Upload files
                athiroy Level 1

                hi

                thank u for your response.

                i don't know php or asp. but i know java.

                i developed my project using flex and java.

                could u suggest me to handle upload a file in flex with java.

                 

                regards

                athi

                • 5. Re: Upload files
                  Matt Le Fevre Level 4

                  I imagine it would be exactly the same type of concept. I don't know enough java to give you an exact coding example, but luckily a 2 second search on google for

                   

                  "uploading files flex java"

                   

                  returned a pretty promising article titled "Uploading a file with Flex and Java"

                   

                  http://www.adobe.com/devnet/flex/articles/file_upload.html

                   

                   

                  i'd recommend starting there

                  1 person found this helpful
                  • 6. Re: Upload files
                    athiroy Level 1

                    hi

                    thank u for your help

                    regards

                    athi

                    • 7. Re: Upload files
                      Karl_Sigiscar_1971 Level 3

                      One of the JSP implementations for file upload:

                       

                       

                      <%@page import="org.apache.commons.fileupload.FileItemFactory"%>
                      <%@page import="org.apache.commons.fileupload.disk.DiskFileItemFactory"%>
                      <%@page import="org.apache.commons.fileupload.servlet.ServletFileUpload"%>
                      <%@page import="org.apache.commons.fileupload.FileItem"%>
                      <%@page import="java.util.List"%>
                      <%@page import="java.util.Iterator"%>
                      <%@page import="java.io.File"%>
                      <%@page import="java.io.FileOutputStream"%>
                      <%@page import="java.io.InputStream"%>

                       

                      <%
                      // Create a factory for disk-based file items
                      FileItemFactory factory = new DiskFileItemFactory();
                      // Create a new file upload handler
                      ServletFileUpload upload = new ServletFileUpload(factory);
                      // Parse the request
                      List /* FileItem */ items = upload.parseRequest(request);

                       

                      // Process the uploaded items
                      Iterator iter = items.iterator();

                       

                      final String BASE_PATH = "C:/Development/apache-tomcat-6.0.20/webapps/fileupload/uploads/";
                      String path = "temp/";

                       

                      while (iter.hasNext()) {
                         FileItem item = (FileItem) iter.next();
                         //handling a normal form-field
                         if (item.isFormField()) {
                            System.out.println("Got a form field");
                            String name = item.getFieldName();
                            String value = item.getString();
                            System.out.println("Name:"+name+",Value:"+value);
                           
                            if(name == "path")
                                path = value;
                           
                         } else {//handling file loads
                            System.out.println("Not form field");
                            String fieldName = item.getFieldName();
                            String fileName = item.getName();
                            String contentType = item.getContentType();
                            boolean isInMemory = item.isInMemory();
                            long sizeInBytes = item.getSize();
                            System.out.println("Field Name:"+fieldName+",File Name:"+fileName);
                            System.out.println("Content Type:"+contentType+",Is In Memory:"+isInMemory+",Size:"+sizeInBytes);

                       

                            byte[] data = item.get();
                           
                            FileOutputStream fileOutSt = new FileOutputStream(BASE_PATH + path + fileName);
                            fileOutSt.write(data);
                            fileOutSt.close();
                           
                            System.out.println(BASE_PATH + path + fileName);
                         }
                      }
                      %>

                      • 8. Re: Upload files
                        mfriasv

                        Hi,

                         

                        I am looking the same but in ASP. I have my FileReference.upload but I need some directions to write a script to upload the file in the server in ASP (vb).

                         

                        I have this. Can anyone tell me if that would work? When I execute the flex app I always get the 2038 i/o error.

                         

                        Public Function importFile(ByVal f As Byte(), ByVal fileName As String) As String
                                Try
                                    Dim ms As New MemoryStream(f)
                                    Dim fs As New FileStream(System.Web.Hosting.HostingEnvironment.MapPath("C:\temp") & fileName, FileMode.Create)
                                    ms.WriteTo(fs)
                                    ms.Close()
                                    fs.Close()
                                    fs.Dispose()
                                    Return "ok"

                         

                                Catch ex As Exception
                                    Return ex.Message.ToString()
                                End Try

                         

                            End Function

                        • 9. Re: Upload files
                          Maria Pieroszkiewicz Level 1

                          I need in my application.

                          How to use ColdFusion and Flex upload pictures to the server

                          I don't know so well the CF to deal with it.