0 Replies Latest reply on Dec 14, 2011 8:22 PM by ros_c

    Help on uploading and downloading of file to/from database.

    ros_c Level 1

      Hi everyone,

        I have problem with the uploading and downloading of files to/from database(store as BLOB) using Flex. I have coded the upload and download function my mxml file as shown below. Is the correct way of doing it ? Do i need to convert anything when i pass the file into my java file ? Cause when I try to download the file and save in my local and when I try to open the file , it actually contain the Content-Deposition n Content-Type in my data file. Any idea how to resolve it?





         <mx:Button label="Upload" click="upload('bailBank');"/> 



      private function upload (bailBank:String):void { 

          if (file.size > 0) { 

           var request:URLRequest = new URLRequest("http://xxxx/UploadFileServlet?referenceNumber="+referenceNum+"&referenceNu="+bailBank+"&fi leName="+file.name);






                  ServletInputStream is = req.getInputStream();

                   byte[] bailkFile=InputStreamToByte(is);

                    entity.setBailBankstFile(Hibernate.createBlob(bailkFile));  -->calling my insert statement




         <mx:Button label="View" click="download('bailBank');"/> 



      private function download (bailBank:String):void { 

           var servleturl="http://xxx/UploadFileServlet?referenceNumber="+referenceNum+"&referenceNu="+bailBank;

           var urlRequest:URLRequest = new URLRequest(servleturl); //servleturl是servlet访问地å&#157;€



           var fileRef:FileReference = new FileReference();

           fileRef.addEventListener(Event.COMPLETE, file_complete); 

           fileRef.addEventListener(ProgressEvent.PROGRESS, file_progress); 





      OutputStream output = resp.getOutputStream();

      Object object = entity.getBailBankstFile();

      byte[] attachmentFile = null;

         if (object != null && object instanceof byte[]) {

          attachmentFile = (byte[]) object;



         InputStream stream = null;