0 Replies Latest reply on Jan 10, 2010 4:49 AM by ahobbsy10

    Question regrading uploading file on Flex and reading the on Java server

    ahobbsy10

      Hello
      I am using Java on the server side and i am uploading a file using file reference on the client side using adobe flex 3 and passing it to the server side using http post and i am having trouble saving the file to database. I am also using hibernate, springframework, Jboss server and Mysql 5 database this is my flex code. I know for a fact that it is hitting the servlet page so i am just can't read the file.
      private function startUpload():void
      {
      if (_arrUploadFiles.length > 0) {
      disableUI();

       

      listFiles.selectedIndex = _numCurrentUpload;
      scrollFiles();
      var sendVars:URLVariables = new URLVariables();
      sendVars.action = "upload";

       

      var request:URLRequest = new URLRequest();
      request.data = sendVars;
      request.url = _strUploadUrl;
      request.method = URLRequestMethod.POST;
      _refUploadFile = new FileReference();
      _refUploadFile = listFiles.selectedItem.file;
      _refUploadFile.addEventListener(ProgressEvent.PROGRESS, onUploadProgress);
      _refUploadFile.addEventListener(Event.COMPLETE, onUploadComplete);
      _refUploadFile.addEventListener(IOErrorEvent.IO_ERROR, onUploadIoError);
      _refUploadFile.addEventListener(SecurityErrorEvent.SECURITY_ERROR, onUploadSecurityError);
      _refUploadFile.upload(request, "file", false);
      }
      }
      This is my java code and i have tried so many different ways of getting this file but have hit a brick wall and i have no other ideas

       

      package com.file.exchange.service;

       

      import javax.servlet.http.HttpServletRequest;
      import javax.servlet.http.HttpServletResponse;
      import javax.xml.parsers.DocumentBuilder;
      import javax.xml.parsers.DocumentBuilderFactory;
      import org.w3c.dom.Document;
      import org.w3c.dom.Element;
      import org.w3c.dom.Node;
      import org.w3c.dom.NodeList;
      import org.xml.sax.InputSource;
      import java.io.*;
      import java.sql.Blob;
      import com.file.exchange.vo.Files;
      import java.util.Date;
      import java.text.DateFormat;
      import java.text.SimpleDateFormat;
      import java.io.IOException;
      import java.io.PrintWriter;
      import java.io.File;
      import java.util.Enumeration;

       

      public class FileUpload extends FileBaseService
      {
      private static final String CONTENT_TYPE = "text/xml; charset=utf-8";

       


      @Override
      protected String getXmlFromOperation(HttpServletRequest request,HttpServletResponse response) throws Exception
      {

       

      //ServletOutputStream servletOutputStream = response.getOutputStream();
      //Object fileObject = new Object(response.getOutputStream().);
      //InputStream is = new InputStream() ;
      //InputStreamReader input = new InputStreamReader(request.getInputStream());
      //BufferedReader buffer = new BufferedReader(input);
      DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
      Date date = new Date();
      String data = "hello world";
      String id = "1";//getCharacterDataFromElement(vID);
      String name = String.valueOf(request.getAttributeNames());//getCharacterDataFromElement(vname);
      String type = ".txt";//getCharacterDataFromElement(vtype);
      String size = "5555";//Long.toString(fileObject.length());//getCharacterDataFromElement(vsize);
      Blob content = org.hibernate.Hibernate.createBlob(data.getBytes());//fisFile);//data.getbytes[]
      String date_uploaded = dateFormat.format(date);
      Files file = getFileDao().uploadFile(Integer.parseInt(id), name, type, Integer.parseInt(size), content, date_uploaded);
      return file.toXml();
      }
      }