File Upload -- MultipartRequest Problem

I use com.oreilly.servlet.MultipartRequest to upload files through a servlet.
This works fine, but when the size of a file exceeds the maximum size,
I need to handle the IOException but it doesn't work.
here is the code:
try {
if (file != null) {
File outputFile = new File(fullPath,fileName);
FileInputStream inFile = new FileInputStream(file);
FileOutputStream outFile = new FileOutputStream(outputFile);
while (inFile.available()>0) {
outFile.write(inFile.read());
inFile.close();
outFile.close();
return (fileName);
catch( java.io.IOException e ) {
System.out.println("DiskFileUpload write failed" + e.toString());
return (null);
catch ( java.lang.Exception le) {
System.out.println("DiskFileUpload write failed" + le.toString());
response.sendRedirect("error.html");

What is the problem you are getting?
Are you getting Page Cannot displayed Browser page?

Similar Messages

  • File Upload element Problem

    Hello All,
    We have a problem regarding the File Upload button in Webdynpro.
    when we upload a file using this element and goto another view and comeback, the upload element is not showing any filename.
    But when debugged, the fileupload context node still has the data. Just it is not showing in the UI.
    Is it an existing problem with File Upload? Or do we have to do anything to make the filename visible.
    Thanks,
    Anand

    Hi,
    this works as designed, see the section on browser details <a href="http://help.sap.com/saphelp_nw70/helpdata/en/b3/be7941601b1d09e10000000a155106/frameset.htm">here</a>
    Regards, Heidi

  • File Upload demo problem

    Hi!, i have a problem with the File Upload Demo when it calls this line:
    hDirectoryObject := JFile.new(directory);
    and the error is: error 6508 "PL/SQL: could not find program unit being called"
    That's ok, but anybody knows why should the program couldnt find the routine ?
    And just one more thing...where can i look for JFile method description ??
    Thanks a lot :) !!
    Cristian.

    Is this 9i or 6i?
    JFile is an imported wrapper for a Java Class - it should be in the Demo form already - you could try a compile all on the file just in case.

  • File Upload / ENCTYPE Problem - Please HELP !!!!!!

    Please HELP !!!
    I have following config. MS Windows Server 2003 with
    Coldfusion 7. Everything is working fine.
    But now I want to upload a file, and there is the problem
    that I have the wrong content type on my action page, and so my
    form field "FileContents" is empty.
    On my action page i have got content_type
    "application/x-www-form-urlencoded" instead of
    "multipart/form-data".
    Here is the code:
    --------------------uploadfileform.cfm--------------------
    <cfoutput>
    <form enctype="multipart/form-data" method="post"
    action="uploadfileaction.cfm" name="uploadForm" id="uploadForm">
    <input name="FileContents" type="file"
    id="FileContents">
    <br>
    <input name="submit" type="submit" value="Upload File">
    </form>
    </cfoutput>
    --------------------uploadfileaction.cfm--------------------
    <cffile action="upload" fileField="FileContents"
    destination="e:\tempdir" nameConflict="MakeUnique">
    If there is anyone who can help me please be so kind and tell
    me the solution.
    Kind Regards!

    On my action page i have got content_type
    "application/x-www-form-urlencoded" instead of
    "multipart/form-data".
    There is no need for that sort of thing on the action page.
    On the action page the cffile tag is enough.
    Everything else seems to be all right, except one. The
    destination attribute should end with a back-slash. The correct
    value is
    destination="e:\tempdir\".

  • (JSP/SERVLET) File upload Character problem form enctype="multipart.....

    Hi,
    When i upload a file from <form> ( jsp page ) and send it to my object class(struts,servlet) , the filename �����.doc are replaced by ?????.doc. in the database.
    I make few test by adding UTF-8 charset and content type to the jsp but still doesn't work...
    Ex :
    String encod = request.getCharacterEncoding();
    if (encod == null || !encod.equals("UTF-8"))
    try
    request.setCharacterEncoding("UTF-8");
    catch (UnsupportedEncodingException e)
    System.err.println("HttpMultipartRequest - : " + e);
    It's not a charset problem in the database because i try to do with an input type="text" and its working. It's just not working with the input type="file".
    And i also add directly ��� character into the database and its working.
    it's will be a pleasure if someone could response to me .
    thanks
    Jonathan

    warnerja,
    Not sure why you always play the part of the
    cross-post police... Seems like waste of effort to
    me.To each his own. I'm not sure why you feel the need
    to question my motives. Also not sure why you have
    posted requests to Sun regarding forum features...
    "Seems like a waste of effort to me.". But I wasn't
    going to call you on it.touch�
    :-)

  • File Upload/Download Problem

    Hi,
    I have a fileupload button. The attributes type is XSTRING, which i bound it with "data" property of download.
    When i download this file with "download" element, it comes in a zip file and as XML files. Only the jpg files are downloaded correctly.
    How can i solve this?
    Thanks.

    Hi,
    I am so sory for my very late answer.
    If you want to upload/download files, you should have a node which includes attributes
    (attribute names are just example ):
    1) filename(type: for example afilename),
    2)mimetype (type : string),
    3) file(type : a data element with type 'RAWSTRING').
    You must match your fileupload element's attributes with them:
    "DATA" attribute --> file ,
    "fileNAME" attribute--> filename,
    "mimeTYPE" attritube -->mimetype.
    When you want to download this file, you should put a filedownload element and match this element's attributes with the node's attributes which i described above.

  • File Upload Concept Problem

    Hi, I am writing a WAS4 webapp which will allow users to upload files to the WAS machine. I've written and deployed apps on WAS4 before and I create a war file and deploy it via the admin console. But something I don't quite understand is that if I create a folder, say 'upload' underneath my context root such that the path is /contextRoot/upload and this folder is inside the war file, can a user upload into this folder?
    If not, then where must I place the folder in order to perform uploads and how can I reference this folder from my java code? Do I give it absolute machine paths, or some other sort of context relative path?

    Did you try using Jakarta FileUpload? It will answer all your questions.
    http://jakarta.apache.org/commons/fileupload/using.html

  • File upload component problem

    hi,
    When i use fileupload component in my page, Turkish characters is not renderind and i see them as question mark. Changing page encoding is not working and solving my problem, too.
    any suggestion would be appreciated.
    Regards...

    I got exact the same problem, but with Chinese characters display. Does that means we can only use upload with English characters? Any solutions in the future?
    Thanks,

  • Problems with File Upload on BEA WLS 6.1

    I encountered a problem with Jason Hunters File Upload Classes.
    When uploading a file I always get this exception:
    java.lang.NoClassDefFoundError: javax/servlet/http/HttpServletRequest
    at com.oreilly.servlet.MultipartRequest.<init>(MultipartRequest.java:175)
    at servlets.uploader.service(uploader.java:21)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
    at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:263)
    at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:200)
    at weblogic.servlet.internal.WebAppServletContext.invokeServlet(WebAppServletContext.java:23
    90)
    at weblogic.servlet.internal.ServletRequestImpl.execute(ServletRequestImpl.java:1959)
    at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:137)
    at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:120)
    The line of code that brings up this exception is:
    multiReq = new MultipartRequest((ServletRequest)request, "c:\\temp", 10485760);
    Going directly with the HttpServletRequest doesn't help.
    Can anybody help me out on this one? Thanks in forward.
    Michael

    The line of code that brings up this exception is:
    multiReq = new
    = new MultipartRequest((ServletRequest)request,
    "c:\\temp", 10485760);
    try this: MultipartRequest multiReq = new MultipartRequest((ServletRequest)request,
    "c:\\temp", 10485760);
    (not sure if that is the problem or not..)

  • Change upload file name with com.oreilly.servlet.MultipartRequest to handle the file upload

    1. when use com.oreilly.servlet.MultipartRequest to handle the file upload, can I change the upload file name .
    2. how com.oreilly.servlet.MultipartReques handle file upload? do it change to byte ?
    what  different?  if I use the following method?
       File uploadedFile = (File) mp.getFile("filename");
                   FileOutputStream fos = new FileOutputStream(filename);
                    byte[] uploadedFileBuf = new byte[(int) uploadedFile.length()];
                   fos.write(data);
                 fos.close();

    My questions are
    1) when use oreilly package to do file upload , it looks like i line of code is enough to store the upload file in the
    file direction.
    MultipartRequest multi =
            new MultipartRequest(request, dirName, 10*1024*1024); // 10MB
    why some example still use FileOutputStream?
    outs = new FileOutputStream(UPLOADDIR+fileName); 
        filePart.writeTo(outs); 
       outs.flush(); 
      outs.close();
    2) can I rename the file name when I use oreilly package?

  • FILE UPLOAD PROBLEM SHOWING THE CONTENTS IN THE SAME BROWSER WINDOW

    Hi,
    This is amit Joshi
    I have uploaded content using input tag of type file and posted to jsp as multipart/form-data type
    in that jsp i am using following code to display the content in browser but only first content is displayed How can i modify it to show all content in the file ..
    <html>
    <head>
    <title>File Upload Display</title>
    </head>
    <body>
    <%
    //ServletOutputStream sout=response.getOutputStream();
    StringBuilder strBuilder = new StringBuilder();
    int count=0;
    String f;
    f=request.getParameter("filedb");
    DBManager dbm = new DBManager();
    //dbm.createTable("mms3");
    //log.info("In JSP : "+ f);
    //dbm.insert_data(f,"mms3");
    %>
    <%
    if (ServletFileUpload.isMultipartContent(request)){
    ServletFileUpload servletFileUpload = new ServletFileUpload(new DiskFileItemFactory());
    List fileItemsList = servletFileUpload.parseRequest(request);
    strBuilder.append("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>").append('\r').append('\n').append("<xpage version=\"1.0\">").append('\r').append('\n');
    String optionalFileName = "";
    FileItem fileItem = null;
    Iterator it = fileItemsList.iterator();
    ServletOutputStream outputStream=null;
    while (it.hasNext()){
    FileItem fileItemTemp = (FileItem)it.next();
    if (fileItemTemp.isFormField()){
    %>
    <b>Name-value Pair Info:</b>
    Field name: <%= fileItemTemp.getFieldName() %>
    Field value: <%= fileItemTemp.getString() %>
    <%
    if (fileItemTemp.getFieldName().equals("filename"))
    optionalFileName = fileItemTemp.getString();
    else
    fileItem = fileItemTemp;
    if (fileItem!=null){
    String fileName = fileItem.getName();
    %>
    <b>Uploaded File Info:</b>
    Content type: <%= fileItem.getContentType() %>
    Field name: <%= fileItem.getFieldName() %>
    File name: <%= fileName %>
    <%
    if(fileItem.getContentType().equals("image/jpeg")) { %>
    File : <p><%
         //response.setContentType("image/gif");
         byte[] bArray=fileItem.get();
         response.setContentType("image/jpeg");
         outputStream=null;
         outputStream= response.getOutputStream();
         outputStream.write(bArray);
         outputStream.flush();
         outputStream.close();
    else if(fileItem.getContentType().equals("text/plain"))
         %> File : <%= fileItem.getString() %>
    <%
    byte[] bArray=fileItem.get();
    response.setContentType("text/plain");
         outputStream = response.getOutputStream();
         out.println();
         outputStream.write(bArray);
         outputStream.flush();
         outputStream.close();
    %> </p> <%
    %>
    </body>
    </html>
    Edited by: Amit_Joshi on Nov 13, 2007 10:58 PM

    Well Well Well..
    That would not work...
    What you have to do is save the uploaded file content on to a location and then pass the fileName as a request parameter to a deidicated which displays the contents of that file.
    Just as an example
    <html>
    <head>
    <title>File Upload Display</title>
    </head>
    <body>
    <%
    //ServletOutputStream sout=response.getOutputStream();
    StringBuilder strBuilder = new StringBuilder();
    int count=0;
    String f;
    f=request.getParameter("filedb");
    DBManager dbm = new DBManager();
    //dbm.createTable("mms3");
    //log.info("In JSP : "+ f);
    //dbm.insert_data(f,"mms3");
    %>
    <%
    if (ServletFileUpload.isMultipartContent(request)){
    ServletFileUpload servletFileUpload = new ServletFileUpload(new DiskFileItemFactory());
    List fileItemsList = servletFileUpload.parseRequest(request);
    strBuilder.append("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>").append('\r').append('\n').append("<xpage version=\"1.0\">").append('\r').append('\n');
    String optionalFileName = "";
    FileItem fileItem = null;
    Iterator it = fileItemsList.iterator();
    ServletOutputStream outputStream=null;
    while (it.hasNext()){
       FileItem fileItemTemp = (FileItem)it.next();
    %>
    Name-value Pair Info:
    Field name: <%= fileItemTemp.getFieldName() %><br/>
    Field value: <%= fileItemTemp.getString() %><br/>
    <%
    if (fileItemTemp.getFieldName().equals("filename"))
        optionalFileName = fileItemTemp.getString();
    if(!fileTempItem.isFormFiled()){
       String fileName = fileItem.getName();
       fileItem.write(optionalFileName);
    %>
    Uploaded File Info:
    Content type: <%= fileItem.getContentType() %><br/>
    Field name: <%= fileItem.getFieldName() %><br/>
    File name: <%= fileName %><br/>
    <%
    if(fileItem.getContentType().equals("image/jpeg") || fileItem.getContentType().equals("image/pjeg")) {
    %>
      <img src="FileServlet?fileName=<%=optionalFileName%>"   
    <%
    %>
    </body>
    </html>a sample code snippet for FileServlet.
    String fileName =  request.getParameter(fileName);
      File file = new File(fileName);
       if(!file.exists())
         return;
      // If JSP
      String mimeType = application.getMimeType("fileName");
           If you are using servlet
           String mimeType = this.getServletContext().getMimeType(fileName);
         response.setContentType(mimeType);  
         response.setHeader("Content-Disposition","inline;filename=\\"+fileName+"\\");
      BufferedOutputStream out1 = null;
      InputStream in = null;
      if(mimeType == null)
         mimeType = "application/octet-stream";
      try{
         in = new FileInputStream(f);
         response.setContentLength(in.available());
         BufferedOutputStream out1 = new BufferedOutputStream(response.getOutputStream(),1024);
         int size = 0;
         byte[] b = new byte[1024];
         while ((size = in.read(b, 0, 1024)) > 0)
            out1.write(b, 0, size);
      }catch(Exception exp){
      }finally{
          if(out1 != null){
             try{
                out1.flush();               
                out1.close();
             }catch(Exception e){}
          if(in != null){
            try{in.close();}catch(Exception e){}
      } Hope that might answer your question :)
    However,this is not the recommended way of doing this make use of MVC pattern.Would be a better approach.
    you might think of googling on this and can findout what is the best practise followed for problems of this sort
    REGARDS,
    RaHuL

  • Threading problem during File Upload with Apache faces upload tag

    First I am going to tell you "My Understanding of how JSF Apache Upload works, Correct me if i am wrong".
    1) Restores View (to show Input box and Browse button to facilitate users to select a file for upload)
    2) Translates Request Parameters to Component Values (Creates equivalent components to update them with request values).
    3) Validates Input(Checks to see whether the User has input the correct file)
    4) Updates Backing Bean or Model to reflect the values.
    5) Renders response to user.
    I am uploading huge files of sizes 400MB and above with the help of JSF apache extensions tag
    <h:form id="uploadForm" enctype="multipart/form-data">
    <x:inputFileUpload style="height:20px;" id="upload" value="#{backingbean.fileContents}" storage="file" size="50" />
    </h:form>
    In the backing bean
    private UploadedFile fileContents;
         public UploadedFile getFileContents() {
              return fileContents;
         public void setFileContents(UploadedFile fileContents) {
              System.out.println("File being uploaded...");
              this.fileContents = fileContents;
    Since, the file size is so huge, I am using temp folder to use for the apache tag instead of memory.
    In web.xml i am using like this
    <filter>
    <filter-name>ExtensionsFilter</filter-name>
    <filter-class>org.apache.myfaces.component.html.util.ExtensionsFilter</filter-class>
    <init-param>
    <param-name>uploadMaxFileSize</param-name>
    <param-value>600m</param-value>
    </init-param>
    <init-param>
    <param-name>uploadThresholdSize</param-name>
    <param-value>10m</param-value>
    </init-param>
         <init-param>
    <param-name>uploadRepositoryPath</param-name>
    <param-value>/uploadfolder/</param-value>
    </init-param>
    </filter>
    <filter-mapping>
    <filter-name>ExtensionsFilter</filter-name>
    <servlet-name>Faces Servlet</servlet-name>
    </filter-mapping>
    The upload process is working perfectly fine.
    Now coming to the problem:
    Suppose one user is logging into the application & uploading say 400MB of files.
    Until these files are linked to the model objects as my understanding of step 2, if second user tries to open the application he gets stuck with the loading page.
    The page gets loaded only after the request files are linked to the component values(Step 2 above) and updates the backing bean's values.
    I don't see any error in the logs. User is getting stuck. The user is getting stuck only when uploading the files. The other operations like searching are not blocking any other activities performed by the user.
    Server used: IBM Application Server V6.0. CPU is normal, memory usage is normal.

    Dear friend,
    i am also trying to upload using the common file upload.
    when try to run the file error is coming
    can give some suggestion.
    can i use if concurrent user file upload at a time

  • File Upload.. Strange Problem..

    im trying to read file data and print it in the browser. I dont want to save the file. just to read the uploaded file which is TAB delimited..
    First time it works fine. but If I browse back button and reload another file and submit. I am getting content of first file and second file. I closed the browser and reopened it but still problem is not resolved. it keeps on adding file content instead of showing current uploaded file. I dont know what to do.
    here is my code
    upload.html
    <html>
    <head>
    <title>File Upload Form</title>
    </head>
    <body>
    Upload File using this..
    <FORM METHOD="POST" ENCTYPE="multipart/form-data" action="uploadFile.jsp">
    File: <input type="file" name="file"><br>
    <input value="Submit" type="submit">
    </form>
    </body>
    </html>
    UploadFile.jsp
    =============
    <%@page language="java" import="java.io.*" %>
    <%@page language="java" import="java.util.*" %>
    <%!
    private BufferedInputStream bis = null;
    int MAX_LINES = 2000;
    private String currentLine = "";
    //private String[] PartNumber;
    //private String[] Quantity;
    public int disp_counter = 0;
    public int mime_counter = 0;
    public int boundary_counter = 0;
    private String content_diposition = null;
    private HttpServletRequest request;
    private javax.servlet.jsp.JspWriter mOut;
    The incoming request needs to be an InputStream before it can be parsed. This method creates an InputStream from the request. The
    request contains the uploaded file contents
    public void setInputStream(HttpServletRequest request, JspWriter _out)throws IOException {
    try{
    bis = new BufferedInputStream(request.getInputStream());
    } catch(IOException e){
    e.printStackTrace();
    this.request = request;
    this.mOut = _out;
    //mOut.println("After setting input Stream<br>");
    private int getRealContentLength() throws Exception
    boundary_counter = readBoundaryLength(bis);
    content_diposition = readContentDisposition(bis);
    //mOut.println(" getRealContentLength() content_diposition ="+content_diposition+"<br>");
    mime_counter = readUntilBody(bis);
    int tmpContentLength = getContentLength();
    int retLength;
    mOut.println(" getRealContentLength() boundary_counter ="+boundary_counter+"<br>");
    mOut.println(" getRealContentLength() content_diposition ="+content_diposition+"<br>");
    mOut.println(" getRealContentLength() disp_counter ="+disp_counter+"<br>");
    mOut.println(" getRealContentLength() mime_counter ="+mime_counter+"<br>");
    mOut.println(" getRealContentLength() tmpContentLength ="+tmpContentLength+"<br>");
    retLength = getContentLength()-boundary_counter-2-mime_counter-disp_counter;
    return retLength;
    private int readBoundaryLength(BufferedInputStream fis) throws Exception{
    //mOut.println("---- Inside readBoundaryLength ----<br>");
    StringBuffer sb = new StringBuffer();
    byte[] b = new byte[1];
    int counter=0;
    while(true){
    try{
    fis.read(b);
    counter++;
    //mOut.println("RB "+counter+"="+b[0]+"<br>");
    sb.append( new String(b));
    //if('\r'==b[0])
    if(13==b[0]){
    fis.read(b);
    sb.append( new String(b));
    //mOut.println("RB next="+b[0]+"<br>");
    break;
    }catch(IOException e){
    e.printStackTrace();
    //mOut.println("----Counter before return="+counter+" STR="+sb.toString()+"----<br>");
    b = null;
    //mOut.println("---- End readBoundaryLength ----<br>");
    return counter+1;
    private int readUntilBody(BufferedInputStream fis) throws Exception{
    byte[] b = new byte[1];
    mime_counter=0;
    int counter = 0;
    StringBuffer sb = new StringBuffer();
    while(true){
    try{
    fis.read(b);
    sb.append(new String(b));
    mime_counter++;
    //mOut.println("RUntilB "+mime_counter+"="+b[0]+"<br>");
    //if('\r'==b[0])
    if(13==b[0])
    counter++;
    if(counter == 2){
    fis.read(b);
    sb.append(new String(b));
    //mOut.println("RUntilB counter=2 "+mime_counter+"="+b[0]+"<br>");
    break;
    }catch(IOException e){
    e.printStackTrace();
    b = null;
    //mOut.println("RUntilB="+sb.toString()+"<br>");
    return mime_counter;
    private int getContentLength(){
    return request.getContentLength();
    private String readContentDisposition(BufferedInputStream fis) throws Exception{
    byte[] b = new byte[1];
    disp_counter=0;
    StringBuffer sb = new StringBuffer();
    while(true){
    try{
    fis.read(b);
    disp_counter++;
    sb.append(new String(b));
    //mOut.println("ReadCD "+disp_counter+"="+b[0]+"<br>");
    //if('\r'==b[0])
    if(13==b[0]){
    for(int i=1; i < 2; i++){
    sb.append(new String(b));
    fis.read(b);
    //mOut.println("ReadCD before break="+b[0]+"<br>");
    break;
    }catch(IOException e){
    e.printStackTrace();
    //mOut.println("----disp_counter before return="+disp_counter+" STR="+sb.toString()+"----<br>");
    b=null;
    disp_counter += 1;
    return sb.toString();
    private String readNumberOfBytes(BufferedInputStream bis, int count) throws Exception{
    byte[] b = new byte[count];
    byte[] tmp = new byte[count];
    int offset = 0;
    int icount = count;
    int i=0;
    String tmpStr = null;
    try{
    while((i = bis.read(b,0,icount)) != -1){
    System.arraycopy(b,0,tmp,offset,i);
    tmpStr = new String( tmp );
    //mOut.println( "*****"+tmpStr );
    if(icount - i > 0) {
    icount = count - i;
    offset +=i;
    continue;
    else
    break;
    }catch(IOException e){
    e.printStackTrace();
    //for (i=0; i<b.length; i++)
    // mOut.println("AC"+i+"="+b+"<br>");
    return tmpStr;
    public String parseFile( ) throws Exception {
    int len = readAll(bis);
    mOut.println("total len="+len+"<br>");
    //in the first phase, throw away the request parameters that are not required
    //in the second phase, grab the required stuff
    int reallength;
    int mod = 0;
    int div = 0;
    //get rid of the unwanted request content
    reallength = getRealContentLength();//this is the orig line
    //mOut.println( "reallength is " + reallength +"<br>");
    //get rid of boundary and content disp header.
    //int bound_len = readBoundaryLength(bis);
    //String content_disp = readContentDisposition(bis);
    //mOut.println( "Xbound_len" + bound_len +"<br>");
    //mOut.println( "xcontent_disp" + content_disp +"<br>");
    //now we are at partnos,qty
    //int body = readUntilBody(bis);
    if(reallength < 2048){
    currentLine += readNumberOfBytes(bis,reallength);
    else{
    div = reallength / 2048;//buffer default size
    mod = reallength % 2048;
    mOut.println("div ="+div+" mod="+mod+"<br>");
    for(int i=0; i < div; i++)
    currentLine += readNumberOfBytes(bis,2048);
    if(mod != 0)
    currentLine += readNumberOfBytes(bis,mod);
    //mOut.println( "currentLine" + currentLine );
    //ExtractPartNumberAndQuantity();
    //mOut.println("total length="+currentLine.length()+"<br>");
    int lastInd = currentLine.lastIndexOf('\r');
    //mOut.println("lastInd="+lastInd+"<br>");
    lastInd = currentLine.lastIndexOf('\r',lastInd-1);
    //mOut.println("lastInd="+lastInd+"<br>");
    currentLine= currentLine.substring(0,lastInd);
    //mOut.println( "currentLine="+currentLine+"<br>" );
    return currentLine;
    %>
    <%
    out.println(" request length="+request.getContentLength()+"<br>");
    setInputStream(request,out);
    String allLines = parseFile();
    out.println("************** Parsing string starts <br>");
    StringBuffer sb = new StringBuffer();
    sb.append( (char)13 );
    sb.append( (char)10 );
    StringTokenizer st = new StringTokenizer( allLines,sb.toString());
    String line = null;
    // skip the first line as this is header...
    if( st.hasMoreTokens() )
    line = st.nextToken();
    while( st.hasMoreTokens() )
    line = st.nextToken();
    out.println(line+"<br>");
    out.flush();
    %>

    err..
    <%!
    private BufferedInputStream bis = null;
    int MAX_LINES = 2000;
    private String currentLine = "";
    //private String[] PartNumber;
    //private String[] Quantity;
    public int disp_counter = 0;
    public int mime_counter = 0;
    public int boundary_counter = 0;
    private String content_diposition = null;
    private HttpServletRequest request;
    private javax.servlet.jsp.JspWriter mOut;
    that's the problem, most likely.... the <%! part to hold all the variables. Particularly coudl've been a problem if you have multple requests at the same time..

  • Problem with File Uploading.

    Hi,
    I have one problem with File Upload component.
    JSP
    <ui:upload binding="#{NewProblem.fileUpload1}" columns="#{SessionBean1.uploadedFile}" id="fileUpload1" labelLevel="3"
    style="left: 24px; top: 24px; position: absolute" validator="#{NewProblem.fileUpload1_validate}"/>
    Java
    UploadedFile uploadedFile = getSessionBean1().getUploadedFile();
    Variable uploadedFile is NULL :(((((((((((
    web.xml
    <context-param>
    <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
    <param-value>client</param-value>
    </context-param>
    <filter>
    <filter-name>UploadFilter</filter-name>
    <filter-class>com.sun.web.ui.util.UploadFilter</filter-class>
    <init-param>
    <param-name>maxSize</param-name>
    <param-value>10000000</param-value>
    </init-param>
    <init-param>
    <param-name>sizeThreshold</param-name>
    <param-value>10024</param-value>
    </init-param>
    </filter>
    Thanks.

    check out the fileUpload article
    Using the File Upload Component
    http://developers.sun.com/prodtech/javatools/jscreator/learning/tutorials/2/file_upload.html

  • Problem with Multi File upload example, help needed

    I got the code from the following location.....
    http://www.adobe.com/devnet/coldfusion/articles/multifile_upload.html
    And I've got it to work to some degree except I cant get the file transfer to work when pressing, Upload.   Below is what my debugger outputs.  Any thoughts on how to fix this or even what it means?
    At the very bottom of this message is the upload.cfm code.......
    Thanks in advance for the help
    <html>
    <head>
      <title>Products - Error</title>
    </head>
    <body>
    <h2>Sorry</h2>
    <p>An error occurred when you requested this page.
    Please email the Webmaster to report this error.
    We will work to correct the problem and apologize
    for the inconvenience.</p>
    <table border=1>
    <tr><td><b>Error Information</b> <br>
      Date and time: 12/07/09 22:25:51 <br>
      Page:  <br>
      Remote Address: 67.170.79.241 <br>
      HTTP Referer: <br>
      Details: ColdFusion cannot determine how to process the tag &lt;CFDOCUMENT&gt;. The tag name may be misspelled.<p>If you are using tags whose names begin with CF but are not ColdFusion tags you should contact Allaire Support. <p>The error occurred while processing an element with a general identifier of (CFDOCUMENT), occupying document position (41:4) to (41:70).<p>The specific sequence of files included or processed is:<code><br><strong>D:\hshome\edejham7\edeweb.com\MultiFileUpload\upload.cfm      </strong></code><br>
      <br>
    </td></tr></table>
    </body>
    </html>
    <!---
    Flex Multi-File Upload Server Side File Handler
    This file is where the upload action from the Flex Multi-File Upload UI points.
    This is the handler the server side half of the upload process.
    --->
    <cftry>
    <!---
    Because flash uploads all files with a binary mime type ("application/ocet-stream") we cannot set cffile to accept specfic mime types.
    The workaround is to check the file type after it arrives on the server and if it is non desireable delete it.
    --->
        <cffile action="upload"
                filefield="filedata"
                destination="#ExpandPath('\')#MultiFileUpload\uploadedfiles\"
                nameconflict="makeunique"
                accept="application/octet-stream"/>
            <!--- Begin checking the file extension of uploaded files --->
            <cfset acceptedFileExtensions = "jpg,jpeg,gif,png,pdf,flv,txt,doc,rtf"/>
            <cfset filecheck = listFindNoCase(acceptedFileExtensions,File.ServerFileExt)/>
    <!---
    If the variable filecheck equals false delete the uploaded file immediatley as it does not match the desired file types
    --->
            <cfif filecheck eq false>
                <cffile action="delete" file="#ExpandPath('\')#MultiFileUpload\uploadedfiles\#File.ServerFile#"/>
            </cfif>
    <!---
    Should any error occur output a pdf with all the details.
    It is difficult to debug an error from this file because no debug information is
    diplayed on page as its called from within the Flash UI.  If your files are not uploading check
    to see if an errordebug.pdf has been generated.
    --->
            <cfcatch type="any">
                <cfdocument format="PDF" overwrite="yes" filename="errordebug.pdf">
                    <cfdump var="#cfcatch#"/>
                </cfdocument>
            </cfcatch>
    </cftry>

    Just 2 things in my test:
    1) I use no accept attribute. Coldfusion is then free to upload any extenstion.
    Restricting the type to application/octet-stream may generate errors. Also, it is unnecessary, because we perform a type check anyway.
    2) I have used #ExpandPath('.')#\ in place of #ExpandPath('\')#
    <cfif isdefined("form.filedata")>
    <cftry>
    <cffile action="upload"
                filefield="filedata"
                destination="#expandPath('.')#\MultiFileUpload\uploadedfiles\"
                nameconflict="makeunique">
            <!--- Begin checking the file extension of uploaded files --->
            <cfset acceptedFileExtensions = "jpg,jpeg,gif,png,pdf,flv,txt,doc,rtf"/>
            <cfset filecheck = listFindNoCase(acceptedFileExtensions,File.ServerFileExt)/>
    <!---
    If the variable filecheck equals false delete the uploaded file immediatley as it does not match the desired file types
    --->
            <cfif filecheck eq false>
                <cffile action="delete" file="#ExpandPath('.')#\MultiFileUpload\uploadedfiles\#File.ServerFile#"/>
                <cfoutput>Uploaded file deleted -- unacceptable extension (#ucase(File.ServerFileExt)#)</cfoutput>.<br>
            </cfif>
    Upload process done!
            <cfcatch type="any">
                There was an error!
                <cfdocument format="PDF" overwrite="yes" filename="errordebug.pdf">
                    <cfdump var="#cfcatch#"/>
                </cfdocument>
            </cfcatch>
    </cftry>
    <cfelse>
    <form method="post" action=<cfoutput>#cgi.script_name#</cfoutput>
            name="uploadForm" enctype="multipart/form-data">
            <input name="filedata" type="file">
            <br>
            <input name="submit" type="submit" value="Upload File">
        </form>
    </cfif>

Maybe you are looking for