0 Replies Latest reply on Apr 24, 2012 10:45 AM by 931412

    Does Application server support file upload feature?


      I was trying to add upload a file feature to my existing application which was developed on Oracle Application Server Portal. The problem i am facing is that, when i define the encrytype of form to multipart/form-data, it doesn't submit the required parameters. i have tried using the classes provided by JavaZoom, org.apache etc. Here is an example code:

      if ((contentType != null) && (contentType.indexOf("multipart/form-data") >= 0)) {
      DataInputStream in = new DataInputStream(request.getInputStream());
      //we are taking the length of Content type data
      int formDataLength = request.getContentLength();
      byte dataBytes[] = new byte[formDataLength];
      int byteRead = 0;
      int totalBytesRead = 0;
      //this loop converting the uploaded file into byte code
      while (totalBytesRead < formDataLength) {
      byteRead = in.read(dataBytes, totalBytesRead, formDataLength);
      totalBytesRead += byteRead;

      String file = new String(dataBytes);
      //for saving the file name
      String saveFile = file.substring(file.indexOf("filename=\"") + 10);
      saveFile = saveFile.substring(0, saveFile.indexOf("\n"));
      saveFile = saveFile.substring(saveFile.lastIndexOf("
      ") + 1,saveFile.indexOf("\""));
      int lastIndex = contentType.lastIndexOf("=");
      String boundary = contentType.substring(lastIndex + 1,contentType.length());
      int pos;
      //extracting the index of file
      pos = file.indexOf("filename=\"");
      pos = file.indexOf("\n", pos) + 1;
      pos = file.indexOf("\n", pos) + 1;
      pos = file.indexOf("\n", pos) + 1;
      int boundaryLocation = file.indexOf(boundary, pos) - 4;
      int startPos = ((file.substring(0, pos)).getBytes()).length;
      int endPos = ((file.substring(0, boundaryLocation)).getBytes()).length;

      // creating a new file with the same name and writing the content in new file
      FileOutputStream fileOut = new FileOutputStream(saveFile);
      fileOut.write(dataBytes, startPos, (endPos - startPos));

      <table border="2"><tr><td>You have successfully upload the file by the name of:
      <% out.println(saveFile); %></td></tr></table> <%

      the problem is, whenever i try to submit the form. contentType.indexOf("multipart/form-data") always returns -1. Hence, its unable to parse the remaining code. My question is: Does oracle application server portal supports the upload file functionality?