Results 1 to 3 of 3

Thread: Code for uploading any file type

  1. #1
    Geek_Guest
    Guest

    Code for uploading any file type

    Question asked by visitor thakkarsaurabh

    I want to write a code for file uploading and file may be of any type i.e. text, jpeg, html etc...... i want to select a file from my machine and i have to save it on our companies database How to do this......


  2. #2
    Junior Member
    Join Date
    Aug 2008
    Answers
    2

    Re: Code for uploading any file type

    Sorry I have not currently code for upload file but I suggest download orally file upload jar and make request's content type is multipart.


  3. #3
    Junior Member
    Join Date
    Aug 2008
    Answers
    1

    Re: Code for uploading any file type

    1.create a html
    <FORM METHOD="POST" ENCTYPE="multipart/form-data" ACTION = "upload.jsp">
    <INPUT TYPE="FILE" NAME="Filename">
    <INPUT TYPE="SUBMIT" VALUE="Submit">
    <INPUT TYPE="RESET" VALUE="Reset">
    </FORM>

    2.upload.jsp
    copy commons-fileupload-1.0.jar in lib folder
    and import org.apache.commons.fileupload.* ; in ur class
    // Check that we have a file upload request
    boolean isMultipart = FileUpload.isMultipartContent(request);

    // Create a new file upload handler
    DiskFileUpload upload = new DiskFileUpload();

    // Set upload parameters
    /*
    upload.setSizeThreshold(yourMaxMemorySize);
    upload.setSizeMax(yourMaxRequestSize);
    upload.setRepositoryPath(yourTempDirectory);
    */

    // Parse the request
    List items = upload.parseRequest(request); /* FileItem */

    // Process the uploaded Field Items
    Iterator iter = items.iterator();
    while (iter.hasNext()) {
    FileItem item = (FileItem) iter.next();

    if (item.isFormField()) {
    processFormField(item);
    }
    }

    // Process the uploaded FILE items
    iter = items.iterator();
    while (iter.hasNext())
    {
    FileItem item = (FileItem) iter.next();

    if (!item.isFormField()) {
    processUploadedFile(item);
    }
    }


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
About us
Applying for a job can be a stressful and frustrating experience, especially for someone who has never done it before. Considering that you are competing for the position with a at least a dozen other applicants, it is imperative that you thoroughly prepare for the job interview, in order to stand a good chance of getting hired. That's where GeekInterview can help.
Interact