JSP Multipart Form File Upload

Good morning to all.
I searched and googled but camu up with little.
I want to upload a file from an HTML form. I have the enctype set etc. I am receiving all of the data on the server boundaries and all. I know there are readymade packages to do this but I'm one of these types that like to know why something works instead of simply plopping a jar on the server and using it (STD java excepted).
My question is how to parse the data. If you read line by line, looking for the boundaries and you are trying to store the file bytes don't the bytes get corrupted when converting to String (in reader.readLine()) if they are not STD ASCII chars?
Can anyone point me in the direction of a good tutorial on the subject?
Thank you in advance.
ST

The basic idea of sending binary data via HTML is to encode into BASE64. This basically involves turning 3 bytes (8-bit) into 4 bytes (6-bit). This is done by representing a 6-bit byte with an ascii character. Instead of me confusing you I've found some code that does it, with lots of helpful comments.
[url http://ostermiller.org/utils/Base64.java.html] dont know if this code works but hey, it looks the part
Ted.

Similar Messages

  • Useful Code of the Day:  Multipart Form File Upload

    So, you want to upload files to your web server, do ya? Well, I've seen this topic posted a few times in the last month or so and many of the response I've seen here haven't included definitive answers. Of course, the actual problems vary, but ultimately, a bunch of people want to do file upload from an applet or application to an existing file upload script (CGI, PHP, JSP, etc.) on a web server. And invariably, there are problems with formatting the HTTP request to get things working.
    Well, I had a need to do the same thing. I realize there are other solutions out there, such as some sample code that comes with Jakarta Commons Upload. But since we all like reusable code, and we also all seem to like reinventing wheels, here's my go at it: MultiPartFormOutputStream!
    MultiPartFormOutputStream is a specialized OutputStream-like class. You create your URLConnection to the server (a static method included can do this for a URL for you, as some of the settings, doInput and doOutput specifically, seem to confuse people). Then get the OutputStream from it and create a boundary string (a static method to create one is provided as well) and pass them to the constructor. Now you have a MultiPartFormOutputStream which you can use to write form fields like text fields, checkboxes, etc., as well as write file data (from Files, InputStreams or raw bytes).
    There are some convenience methods for writing primative type values as well as strings, but any higher level objects (aside from Files or InputStreams) aren't supported. (You can always serialize and pass the raw bytes.)
    Sample usage code is below. Also, any recommendations for improvement are requested. The code was tested with the Jakarta Struts.
    import java.io.*;
    import java.net.*;
    * <code>MultiPartFormOutputStream</code> is used to write
    * "multipart/form-data" to a <code>java.net.URLConnection</code> for
    * POSTing.  This is primarily for file uploading to HTTP servers. 
    * @since  JDK1.3
    public class MultiPartFormOutputStream {
          * The line end characters. 
         private static final String NEWLINE = "\r\n";
          * The boundary prefix. 
         private static final String PREFIX = "--";
          * The output stream to write to. 
         private DataOutputStream out = null;
          * The multipart boundary string. 
         private String boundary = null;
          * Creates a new <code>MultiPartFormOutputStream</code> object using
          * the specified output stream and boundary.  The boundary is required
          * to be created before using this method, as described in the
          * description for the <code>getContentType(String)</code> method. 
          * The boundary is only checked for <code>null</code> or empty string,
          * but it is recommended to be at least 6 characters.  (Or use the
          * static createBoundary() method to create one.)
          * @param  os        the output stream
          * @param  boundary  the boundary
          * @see  #createBoundary()
          * @see  #getContentType(String)
         public MultiPartFormOutputStream(OutputStream os, String boundary) {
              if(os == null) {
                   throw new IllegalArgumentException("Output stream is required.");
              if(boundary == null || boundary.length() == 0) {
                   throw new IllegalArgumentException("Boundary stream is required.");
              this.out = new DataOutputStream(os);
              this.boundary = boundary;
          * Writes an boolean field value. 
          * @param  name   the field name (required)
          * @param  value  the field value
          * @throws  java.io.IOException  on input/output errors
         public void writeField(String name, boolean value)
                   throws java.io.IOException {
              writeField(name, new Boolean(value).toString());
          * Writes an double field value. 
          * @param  name   the field name (required)
          * @param  value  the field value
          * @throws  java.io.IOException  on input/output errors
         public void writeField(String name, double value)
                   throws java.io.IOException {
              writeField(name, Double.toString(value));
          * Writes an float field value. 
          * @param  name   the field name (required)
          * @param  value  the field value
          * @throws  java.io.IOException  on input/output errors
         public void writeField(String name, float value)
                   throws java.io.IOException {
              writeField(name, Float.toString(value));
          * Writes an long field value. 
          * @param  name   the field name (required)
          * @param  value  the field value
          * @throws  java.io.IOException  on input/output errors
         public void writeField(String name, long value)
                   throws java.io.IOException {
              writeField(name, Long.toString(value));
          * Writes an int field value. 
          * @param  name   the field name (required)
          * @param  value  the field value
          * @throws  java.io.IOException  on input/output errors
         public void writeField(String name, int value)
                   throws java.io.IOException {
              writeField(name, Integer.toString(value));
          * Writes an short field value. 
          * @param  name   the field name (required)
          * @param  value  the field value
          * @throws  java.io.IOException  on input/output errors
         public void writeField(String name, short value)
                   throws java.io.IOException {
              writeField(name, Short.toString(value));
          * Writes an char field value. 
          * @param  name   the field name (required)
          * @param  value  the field value
          * @throws  java.io.IOException  on input/output errors
         public void writeField(String name, char value)
                   throws java.io.IOException {
              writeField(name, new Character(value).toString());
          * Writes an string field value.  If the value is null, an empty string
          * is sent (""). 
          * @param  name   the field name (required)
          * @param  value  the field value
          * @throws  java.io.IOException  on input/output errors
         public void writeField(String name, String value)
                   throws java.io.IOException {
              if(name == null) {
                   throw new IllegalArgumentException("Name cannot be null or empty.");
              if(value == null) {
                   value = "";
              --boundary\r\n
              Content-Disposition: form-data; name="<fieldName>"\r\n
              \r\n
              <value>\r\n
              // write boundary
              out.writeBytes(PREFIX);
              out.writeBytes(boundary);
              out.writeBytes(NEWLINE);
              // write content header
              out.writeBytes("Content-Disposition: form-data; name=\"" + name + "\"");
              out.writeBytes(NEWLINE);
              out.writeBytes(NEWLINE);
              // write content
              out.writeBytes(value);
              out.writeBytes(NEWLINE);
              out.flush();
          * Writes a file's contents.  If the file is null, does not exists, or
          * is a directory, a <code>java.lang.IllegalArgumentException</code>
          * will be thrown. 
          * @param  name      the field name
          * @param  mimeType  the file content type (optional, recommended)
          * @param  file      the file (the file must exist)
          * @throws  java.io.IOException  on input/output errors
         public void writeFile(String name, String mimeType, File file)
                   throws java.io.IOException {
              if(file == null) {
                   throw new IllegalArgumentException("File cannot be null.");
              if(!file.exists()) {
                   throw new IllegalArgumentException("File does not exist.");
              if(file.isDirectory()) {
                   throw new IllegalArgumentException("File cannot be a directory.");
              writeFile(name, mimeType, file.getCanonicalPath(), new FileInputStream(file));
          * Writes a input stream's contents.  If the input stream is null, a
          * <code>java.lang.IllegalArgumentException</code> will be thrown. 
          * @param  name      the field name
          * @param  mimeType  the file content type (optional, recommended)
          * @param  fileName  the file name (required)
          * @param  is        the input stream
          * @throws  java.io.IOException  on input/output errors
         public void writeFile(String name, String mimeType,
                   String fileName, InputStream is)
                   throws java.io.IOException {
              if(is == null) {
                   throw new IllegalArgumentException("Input stream cannot be null.");
              if(fileName == null || fileName.length() == 0) {
                   throw new IllegalArgumentException("File name cannot be null or empty.");
              --boundary\r\n
              Content-Disposition: form-data; name="<fieldName>"; filename="<filename>"\r\n
              Content-Type: <mime-type>\r\n
              \r\n
              <file-data>\r\n
              // write boundary
              out.writeBytes(PREFIX);
              out.writeBytes(boundary);
              out.writeBytes(NEWLINE);
              // write content header
              out.writeBytes("Content-Disposition: form-data; name=\"" + name +
                   "\"; filename=\"" + fileName + "\"");
              out.writeBytes(NEWLINE);
              if(mimeType != null) {
                   out.writeBytes("Content-Type: " + mimeType);
                   out.writeBytes(NEWLINE);
              out.writeBytes(NEWLINE);
              // write content
              byte[] data = new byte[1024];
              int r = 0;
              while((r = is.read(data, 0, data.length)) != -1) {
                   out.write(data, 0, r);
              // close input stream, but ignore any possible exception for it
              try {
                   is.close();
              } catch(Exception e) {}
              out.writeBytes(NEWLINE);
              out.flush();
          * Writes the given bytes.  The bytes are assumed to be the contents
          * of a file, and will be sent as such.  If the data is null, a
          * <code>java.lang.IllegalArgumentException</code> will be thrown. 
          * @param  name      the field name
          * @param  mimeType  the file content type (optional, recommended)
          * @param  fileName  the file name (required)
          * @param  data      the file data
          * @throws  java.io.IOException  on input/output errors
         public void writeFile(String name, String mimeType,
                   String fileName, byte[] data)
                   throws java.io.IOException {
              if(data == null) {
                   throw new IllegalArgumentException("Data cannot be null.");
              if(fileName == null || fileName.length() == 0) {
                   throw new IllegalArgumentException("File name cannot be null or empty.");
              --boundary\r\n
              Content-Disposition: form-data; name="<fieldName>"; filename="<filename>"\r\n
              Content-Type: <mime-type>\r\n
              \r\n
              <file-data>\r\n
              // write boundary
              out.writeBytes(PREFIX);
              out.writeBytes(boundary);
              out.writeBytes(NEWLINE);
              // write content header
              out.writeBytes("Content-Disposition: form-data; name=\"" + name +
                   "\"; filename=\"" + fileName + "\"");
              out.writeBytes(NEWLINE);
              if(mimeType != null) {
                   out.writeBytes("Content-Type: " + mimeType);
                   out.writeBytes(NEWLINE);
              out.writeBytes(NEWLINE);
              // write content
              out.write(data, 0, data.length);
              out.writeBytes(NEWLINE);
              out.flush();
          * Flushes the stream.  Actually, this method does nothing, as the only
          * write methods are highly specialized and automatically flush. 
          * @throws  java.io.IOException  on input/output errors
         public void flush() throws java.io.IOException {
              // out.flush();
          * Closes the stream.  <br />
          * <br />
          * <b>NOTE:</b> This method <b>MUST</b> be called to finalize the
          * multipart stream.
          * @throws  java.io.IOException  on input/output errors
         public void close() throws java.io.IOException {
              // write final boundary
              out.writeBytes(PREFIX);
              out.writeBytes(boundary);
              out.writeBytes(PREFIX);
              out.writeBytes(NEWLINE);
              out.flush();
              out.close();
          * Gets the multipart boundary string being used by this stream. 
          * @return  the boundary
         public String getBoundary() {
              return this.boundary;
          * Creates a new <code>java.net.URLConnection</code> object from the
          * specified <code>java.net.URL</code>.  This is a convenience method
          * which will set the <code>doInput</code>, <code>doOutput</code>,
          * <code>useCaches</code> and <code>defaultUseCaches</code> fields to
          * the appropriate settings in the correct order. 
          * @return  a <code>java.net.URLConnection</code> object for the URL
          * @throws  java.io.IOException  on input/output errors
         public static URLConnection createConnection(URL url)
                   throws java.io.IOException {
              URLConnection urlConn = url.openConnection();
              if(urlConn instanceof HttpURLConnection) {
                   HttpURLConnection httpConn = (HttpURLConnection)urlConn;
                   httpConn.setRequestMethod("POST");
              urlConn.setDoInput(true);
              urlConn.setDoOutput(true);
              urlConn.setUseCaches(false);
              urlConn.setDefaultUseCaches(false);
              return urlConn;
          * Creates a multipart boundary string by concatenating 20 hyphens (-)
          * and the hexadecimal (base-16) representation of the current time in
          * milliseconds. 
          * @return  a multipart boundary string
          * @see  #getContentType(String)
         public static String createBoundary() {
              return "--------------------" +
                   Long.toString(System.currentTimeMillis(), 16);
          * Gets the content type string suitable for the
          * <code>java.net.URLConnection</code> which includes the multipart
          * boundary string.  <br />
          * <br />
          * This method is static because, due to the nature of the
          * <code>java.net.URLConnection</code> class, once the output stream
          * for the connection is acquired, it's too late to set the content
          * type (or any other request parameter).  So one has to create a
          * multipart boundary string first before using this class, such as
          * with the <code>createBoundary()</code> method. 
          * @param  boundary  the boundary string
          * @return  the content type string
          * @see  #createBoundary()
         public static String getContentType(String boundary) {
              return "multipart/form-data; boundary=" + boundary;
    }Usage: (try/catch left out to shorten the post a bit)
    URL url = new URL("http://www.domain.com/webems/upload.do");
    // create a boundary string
    String boundary = MultiPartFormOutputStream.createBoundary();
    URLConnection urlConn = MultiPartFormOutputStream.createConnection(url);
    urlConn.setRequestProperty("Accept", "*/*");
    urlConn.setRequestProperty("Content-Type",
         MultiPartFormOutputStream.getContentType(boundary));
    // set some other request headers...
    urlConn.setRequestProperty("Connection", "Keep-Alive");
    urlConn.setRequestProperty("Cache-Control", "no-cache");
    // no need to connect cuz getOutputStream() does it
    MultiPartFormOutputStream out =
         new MultiPartFormOutputStream(urlConn.getOutputStream(), boundary);
    // write a text field element
    out.writeField("myText", "text field text");
    // upload a file
    out.writeFile("myFile", "text/plain", new File("C:\\test.txt"));
    // can also write bytes directly
    //out.writeFile("myFile", "text/plain", "C:\\test.txt",
    //     "This is some file text.".getBytes("ASCII"));
    out.close();
    // read response from server
    BufferedReader in = new BufferedReader(
         new InputStreamReader(urlConn.getInputStream()));
    String line = "";
    while((line = in.readLine()) != null) {
          System.out.println(line);
    in.close();------
    "Useful Code of the Day" is supplied by the person who posted this message. This code is not guaranteed by any warranty whatsoever. The code is free to use and modify as you see fit. The code was tested and worked for the author. If anyone else has some useful code, feel free to post it under this heading.

    I have a weird problem here. I'm using the Java POST (slightly altered for my purposes) mechanism but the receiving script doesn't receive any form variables (neither files nor regular form fields). If I try using the same receiving script with a regular upload form, it works. Because I've been pulling my hair out, I even went so far as to analyze the ip-packets. I can see that the file is actually sent through the Java POST mecahnism. Anybody any ideas. Here's the ip-packet of the failing upload:
    ----- Hypertext Transfer Protocol -----
    HTTP: POST /fotoxs/upload.cfm HTTP/1.1
    HTTP: Connection: Keep-Alive
    HTTP: Content-Type: multipart/form-data; boundary=-----------------------------fb2649be18
    HTTP: User-Agent: Mozilla/4.7 [en] (WinNT; U)
    HTTP: Accept-Language: en-us
    HTTP: Accept-Encoding: gzip, deflate
    HTTP: Accept: image/gif, image/jpeg, image/pjpeg, */*
    HTTP: CACHE-CONTROL: no-cache
    HTTP: Host: newmarc
    HTTP: Content-Length: 15511
    ----- Hypertext Transfer Protocol -----
    HTTP: -----------------------------fb2649be18
    HTTP: Content-Disposition: form-data; name="uploadFile"; filename="out.jpg"
    HTTP: Content-Type: image/jpeg
    HTTP: Data
    ....[data packets]
    The one that works (from the regular post) is as follows:
    ----- Hypertext Transfer Protocol -----
    HTTP: POST /fotoxs/upload.cfm HTTP/1.1
    HTTP: Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-gsarcade-launch, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*
    HTTP: Referer: http://localhost:8500/fotoxs/test.cfm
    HTTP: Accept-Language: nl
    HTTP: Content-Type: multipart/form-data; boundary=---------------------------7d41961f201c0
    HTTP: Accept-Encoding: gzip, deflate
    HTTP: User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)
    HTTP: Host: newmarc
    HTTP: Content-Length: 59022
    HTTP: Connection: Keep-Alive
    HTTP: Cache-Control: no-cache
    ----- Hypertext Transfer Protocol -----
    HTTP: -----------------------------7d41961f201c0
    HTTP: Content-Disposition: form-data; name="FiletoUpload"; filename="D:\My Documents\My Pictures\fotomarc.jpg"
    HTTP: Content-Type: image/pjpeg
    HTTP: Data
    ----- Hypertext Transfer Protocol -----
    HTTP: HTTP/1.1 100 Continue
    HTTP: Server: Microsoft-IIS/5.0
    HTTP: Date: Sun, 07 Mar 2004 17:14:41 GMT
    ....[data packets]
    One detail worth mentioning is that I don't read a file from harddisk, I'm streaming it directly to the connection outputstream from an image compression utility. But I can see the data in the ip-packets, and even if that somehow didn't work right, it doesn't explaing the fact that the receiving scripts reports no form fields whatsoever.
    Thanks,
    Marc

  • Multipart form (file upload) processing in providers

    Hello,
    Just want to find out if anyone has successfully implemented a file upload mechanism within a Portal channel.
    According to the Provider API (http://docs.sun.com/source/816-6428-10/com/sun/portal/providers/Provider.html), the wrapped request/response objects do not support several methods that are essential to process file uploads, namely "getContentLength" and "getInputStream". I am currently trying to use the Apache commons-fileupload utility which uses those methods to process file uploads. This is also the case for another popular file upload utility from servlets.com.
    Does anyone have any info/explanation regarding this limitation in Portal Server 6, and any workarounds to this issue. One workaround is to have a window popup that interacts directly with an external webapp.
    Any ideas/suggestions will be appreciated, thanks in advance.
    jeff

    Hi Jeff,
    The Sun ONE Portal Server DesktopServlet does not have the ability to process a request with the content encoding type of multipart/form-data. DesktopServlet does not pass the input stream for the request on to the Provider.
    To accomplish handling of multipart/form-data type requests, it is necessary to create a companion servlet or JSP that process the multipart/form-data. This servlet can then pass control back to the Portal channel. The data from the file can be shared between the servlet and the provider by using static Java members or by storing the data in a back-end database and then passing a reference to the data over to the provider.
    Sanjeev

  • JSP : latest  JSTL, File Upload from web form Client to Server Question!

    I understand that within a JSP, It is possible to read a file from the Client by opening a Stream somehow.
    How do I code, within jsp/servlet (non tag) java code inside <% %>
    blocks, WITHOUT openening a new connection to the URL, an InputStream from a client web browser form, from a file upload coded using
    <input type="file" name="file1"/> ?
    I have previously achieved this quite simply with a FileInputStream
    with the previous version of JSTL.
    How may I do this with the latest version of JSTL, with this index.jsp?
    -with a simple text file.
    -with a Binary file (with DataInputStream)?
    <%--
    Document : index
    Created on : 27/01/2009, 3:08:32 PM
    Author : Zachary Mitchell
    --%>
    <%@page contentType="text/html" pageEncoding="UTF-8"%>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>JSP Page</title>
    </head>
    <body>
    <h1 align="center">Hello World!</h1>
    <form name="form1" method ="POST" >
    <table align="center">
    <tr>
    <td>
    <input name="file1" type="file" align="center"></input>
    </td>
    </tr>
    <tr>
    <td>
    <input type="submit" value="submit" action="index.jsp" ></input>
    </td>
    </tr>
    </table>
    </form>
    <!--*********************************************************************** -->
    <%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c" %>
    <%@page import = "java.io.*" %>
    <c:if test="${pageContext.request.method=='POST'}">
    <%
    File fileName = new File(request.getParameter("file1"));
    out.println(fileName.toString());
    FileInputStream stream = new FileInputStream(fileName);
    out.println(stream.toString());
    %>
    </c:if>
    <!--*********************************************************************** -->
    </body>
    </html>

    If I have:
    <!-- ***********************************************************************************-->
    <form name="form1" method="POST" enctype="multipart/form-data">
    <input name="file1" type="file"/>
    <input name="submit1" type="submit" value="Submit" action="index.jsp"/>
    </form>
    <!-- ***********************************************************************************-->
    and run this in an index.jsp, use browse to select my text file, and click SUBMIT.
    I can use:
    InputStreamReader reader = new InputStreamReader(new DataInputStream(request.getInputStream()))
    BufferedReader bufferedReader = new BufferedReader(reader);
    bufferedReader.readLine();...
    However, these is some HTML/POST related content around what multiple readLine();
    calls return.
    Is there an easy way, like using "${param.file1}",
    aside from [http://commons.apache.org/fileupload/|http://commons.apache.org/fileupload/],
    maybe using servlet style code, to get the File contents from a remote Client,
    to the remote Server servlet engine, AVOIDING ANY SUPERFLUOUS CONTENT,
    using version 1.12 of the JSTL, JSP 2.0,Tomcat 6?
    Just politely, yes, no, and how?
    Edited by: Zac1234 on Jan 29, 2009 3:27 AM
    Edited by: Zac1234 on Feb 1, 2009 8:29 PM

  • Using JSP, HTML Form for uploading image  in order to be saved into a db

    I have a HTML form and I am using <input type="file"> tag. The problem is that I don't know the Java code needed for the JSP page in order to get through the path and get the image(of course I refer to binary object). Below there is the html code
    <%@ page language="java" import="java.sql.*, java.awt.*, java.awt.Event, java.util.*, java.io.*, javax.servlet.*"%>
    <html>
    <head>
    </head>
    <body>
    <div align="left"></div>
    <form action="action.jsp" method="POST" name="form"
    <h1>Add Data</h1>
    <table>
    <tr>
    <td>Name</td>
    <td><input type="text" name="Name" value="" /></td>
    </tr>
    <tr>
    <td>Last Name</td>
    <td><input type="text" name="lastname" value=""/></td>
    </tr>
    <tr>
    <td>Studies</td>
    <td><textarea name="studies" rows="4" cols="20" >
    </textarea>
    </td>
    </tr>
    <tr>
    <td>General Data</td>
    <td><textarea name="gendata" rows="4" cols="20">
    </textarea>
    </td>
    </tr>
    <tr>
    <td>Photo</td>
    <td><input type="File" name="photo"/></td>
    </tr>
    <tr>
    <td> <input type="submit" > </td>
    </tr>
    </table>
    </form>
    If you want to view the Personnel List click here<br>
    Go to index
    </body>
    </html>

    A JSP should not be involved in this. The browser will offer a way to specify a file, and the target of the form should be a servlet that can handle multipart uploads. JSPs should not process any input.
    More info: http://www.jguru.com/faq/view.jsp?EID=160 or Google

  • RE: HTTP File upload using WebEnterprise

    AFAIK, WebEnterprise does not support the multipart-mime file upload
    feature. I think this is something that is targeted for the next
    release.
    On a project here we wrote our own cgi program to handle file uploads,
    but unfortunately this was not integrated with the rest of the Forte
    backend. The suggestion from Forte was to make C++ calls into our Forte
    service objects from our CGI. We haven't yet implemented this, but it
    certainly seems like it will be possible.
    By all means, let us know if you find a better mechanism than this.
    It's certainly not the cleanest in the world.
    Sam Yates
    Systems Analyst
    Amgen, Inc
    [email protected]
    To unsubscribe, email '[email protected]' with
    'unsubscribe forte-users' as the body of the message.
    Searchable thread archive <URL:http://pinehurst.sageit.com/listarchive/>

    Hi,
    You should have a parameter called ServiceName in your request
    (either in the URL or as a hidden parameter in the form) for any request
    you send to fortecgi. The cgi uses this information to send your request
    to the proper forte application.
    In your example you would need something like this
    <FORM ENCTYPE=3D"multipart/form-data" ACTION=3D"...." METHOD=3DPOST>
    Send this file: <INPUT NAME=3D"userfile" TYPE=3D"file">
    <INPUT TYPE=3D"submit" VALUE=3D"Send File">
    <INPUT TYPE="Hidden",Name="ServiceName",Value="MyService">
    </FORM>
    MyService is the name is the name you have given for the service when
    you call EnableAccess in your subclass of HTTPAccess.
    This is all explained in the Web Enterprise /SDK manual.
    Note : You would also need a parameter PageName when using Web SDK. I
    have not used Web Enterprise yet but I presume it is the same there too.
    Hope this helps
    Santha Athiappan
    Get Your Private, Free Email at http://www.hotmail.com
    To unsubscribe, email '[email protected]' with
    'unsubscribe forte-users' as the body of the message.
    Searchable thread archive <URL:http://pinehurst.sageit.com/listarchive/>

  • Error in file upload servlet

    Hi there,
              I am experiencing some problems with a WL 5.1 sp8 server trying to do a
              form (multipart/form-data) upload of a file.
              I am using the com.oreilly package but get a Corrupt form data error
              when instatiating the MultipartRequest object in the contructor of the
              MultipartParser
              Object.
              Have anyone solved this on a WL 5.1 using the IIS plugin??
              regards
              Klaus Petersen
              Alpha-Gruppen A/S
              [email protected]
              

    Hi there,
              I am experiencing some problems with a WL 5.1 sp8 server trying to do a
              form (multipart/form-data) upload of a file.
              I am using the com.oreilly package but get a Corrupt form data error
              when instatiating the MultipartRequest object in the contructor of the
              MultipartParser
              Object.
              Have anyone solved this on a WL 5.1 using the IIS plugin??
              regards
              Klaus Petersen
              Alpha-Gruppen A/S
              [email protected]
              

  • Unable to install File Upload Utility in AIX system

    Hello,
    I installed the Forms File Upload Utility, through CGI, following the steps described in the html
    document provided with the utility. That is:
    - i copied the files UploadClient.jar.sig and UploadServer.jar to the directory
    /ias102/6iserver/forms60/java;
    - i edited the .profile file, for the variable CLASSPATH to include the forms60/java directory:
    CLASSPATH=/ias102/6iserver/forms60/java:/ias102/6iserver/forms60/java/UploadServer.jar:/ias102/6iserver/discwb4/classes/locator.jar:/usr/java131/jre/lib/rt.jar:
    - i edited the .profile file, for the variable PATH to include the requested directories (Forms \bin and \bin\classic):
    PATH=/ias102/6iserver/lib:/ias102/6iserver/bin:/usr/java131/jre/bin/classic/:/us
    r/java13
    1/bin:$PATH
    (i also tried editing the CLASSPATH and PATH variables in the forms60.sh and forms60_server files)
    - on my machine (client machine) i installed the PJC.x509 certificate;
    After this installation, i included the Demo Form provided with the utility in my test application, and then i executed
    the form.
    I tried to upload a file but i got the following error: "FRM-40735: WHEN-BUTTON-PRESSED trigger raised unhandled exception ORA-06508"
    I looked in the html document, in the "Troubleshooting" section, and i did a test pressing
    the Key-Listval (Control+L by default), that would pop up a dialog containing
    the current CLASSPATH, but instead i got the following error:
    "FRM-40735: KEY-LISTVAL trigger raised unhandled exception ORA-105100."
    In the html said that "If this fails then this is because Forms cannot instanciate any Java code
    at all".
    Do i need to add any more environment settings?
    Thanks, Jorge

    There are probably several environment variables which need to be set in order for the Forms runtime to communicate with Java. However, to where they point will depend on which Java home you choose to use. For Forms 6.x, you must use the equivalent of JDK 1.1.8 or 1.2.2. These versions are included in the Oracle home. If you try using a newer version (like the one installed on the OS) you will likely have problems.
    Verify these env variables point to the appropriate locations to use the jdk/jre in the Oracle Home:
    PATH
    CLASSPATH
    LIBPATH
    LD_LIBRARY_PATH
    JAVA_HOME
    Additionally, ensure that your CLASSPATH includes references to the following jar files:
    importer.jar
    rt.jar

  • Struts file upload without interMedia under ADF

    Can this be done ?
    I have an existing table with the following columns:
    Content BLOB
    MimeType VARCHAR2
    FileName VARCHAR2
    and more

    Very frustrated :(
    Trying to find an answer to my question above.
    If I Add a transient OrdDocDomain to the Entity/View Layer.
    Map this into the UIModel (drag-drop onto JSP as struts file upload) so a FormFile object is available in the struts Action layer.
    Override 'processUpdateModel' so I can obtain a reference to the FormFile object.
    In the commit event of the Action class, take the referenced FormFile and set the BLOB like follows;
    newRow.setAttribute("FileData",
    new BlobDomain(uploadFile.getFileData())
    Then call into the internal commit operation.
    The following exception is raised;
    04/11/19 07:32:18 java.lang.ArrayIndexOutOfBoundsException: 0
    04/11/19 07:32:18      at oracle.jbo.client.remote.OrdClientPostListener.notifyClientPostAfter(OrdClientUtil.java:135)
    04/11/19 07:32:18      at oracle.jbo.client.remote.ApplicationModuleImpl.postChanges(ApplicationModuleImpl.java:796)
    The transient OrdDocDomain has registered a listener.
    How can I remove this listener. The transient has a method 'removeListenerFromTransaction()' with the comment 'Internal: Applications should not use this method.' and no other references ?
    Does anyone know how the listener can be removed or better still, not be registered with the transaction.

  • Upload a file to the server - multipart/form-data ?

    I need to upload a file from my local machine to the server from a jsp page. I was asked to use a form with ENCTYPE = "multipart/form-data". but I am not sure how it works. Can any one enlighten me on the process or is there any other way to do it.
    null

    You can find the jsp source & the java sources which exactly does that in the iFS CMS sample code section. Go to Products -> Internet File system -> sample code -> Content Management System. This application allows the user to upload files from a local file system into iFS. This application creates the file in the iFS repository. You may want to save it in the file system of the web server. You may have to make little changes but the functionality is exactly what you are looking for.
    Hope this helps.
    Rajesh

  • File Upload with jsp & MultiPart

    Hi all,
    i've got a problem uploading a file from a multipart form.
    The file is correctly uploaded and i can open it, but I can't get the file name,
    In multipart.jsp fileName print out a null.
    Below the code. Can someone telle me where the error is?
    Thank's
    Kalvin
    this is the first page:
    prova.jsp:
    <form name="frmUp" action="multipart.jsp" method="POST" enctype="multipart/form-data">
    <input type="file" name="file"><br>
    <input type="submit">
    </form>
    multipart.jsp:
    <%
    String fileName = request.getParameter("nomeFile");
    String pathFile = "/myPath/";
    InputStream is = request.getInputStream();
    out.println("File name:"+fileName+"<br>");
    UploadFile uf = new UploadFile(pathFile, fileName);
    if (uf.upload(is))
         out.println("OK<br>");
    else
         out.println("NO OK <br>");
    %>

    you have to get the filename from UploadFile object probably. You definitely can't get it from request cuz multipart forms are handled specially. If it saves the file properly, then it's probably assuming a null filename means to use the name as it was uploaded, but UploadFile should be able to give you a File object for where the file was put.

  • Hi, I am using HP11 and iPlanet web server. When trying to upload files over HTTP using FORM ENCTYPE="multipart/form-data" that are bigger than a few Kilobytes i get a 408 error. (client timeout).

    Hi, I am using HP11 and iPlanet web server. When trying to upload files over HTTP using FORM ENCTYPE="multipart/form-data" that are bigger than a few Kilobytes i get a 408 error. (client timeout). It is as if the server has decided that the client has timed out during the file upload. The default setting is 30 seconds for AcceptTimeout in the magnus.conf file. This should be ample to get the file across, even increasing this to 2 minutes just produces the same error after 2 minutes. Any help appreciated. Apologies if this is not the correct forum for this, I couldn't see one for iPlanet and Web, many thanks, Kieran.

    Hi,
    You didnt mention which version of IWS. follow these steps.
    (1)Goto Web Server Administration Server, select the server you want to manage.
    (2)Select Preference >> Perfomance Tuning.
    (3)set HTTP Persistent Connection Timeout to your choice (eg 180 sec for three minutes)
    (4) Apply changes and restart the server.
    *Setting the timeout to a lower value, however, may    prevent the transfer of large files as timeout does not refer to the time that the connection has been idle. For example, if you are using a 2400 baud modem, and the request timeout is set to 180 seconds, then the maximum file size that can be transferred before   the connection is closed is 432000 bits (2400 multiplied by 180)
    Regards
    T.Raghulan
    [email protected]

  • HTML multipart form is not working in jsp page

    Hi
    i have jsp page, has a HTML from with file upload field , when i click the send button , nothing happened as if the button did not submit the form. ie the message at line 12 is not printed out.
    can any one help please.
    <%@ page errorPage="..\error\error.jsp" %>
    <%@ page pageEncoding="windows-1256" %>
    <%@ page language="java" import="javazoom.upload.*,java.util.*,java.sql.ResultSet" %>
    <jsp:useBean id="upBean" scope="page" class="javazoom.upload.UploadBean" >
      <jsp:setProperty name="upBean" property="folderstore" value="<%=request.getRealPath("thuraya//uploads")%>"  />
    </jsp:useBean>
    <jsp:useBean id="dbc" class="mypackage.DBConnection" scope="session" />
    <!-- add news-->
    <%
    if(request.getParameter("addBTN") != null){
            out.println("addbtn");
            //do upload file + insert in database
             if (MultipartFormDataRequest.isMultipartFormData(request))
             // Uses MultipartFormDataRequest to parse the HTTP request.
             MultipartFormDataRequest mrequest = new MultipartFormDataRequest(request);
             String todo = null;
             if (mrequest != null) todo = mrequest.getParameter("todo");
                 if ( (todo != null) && (todo.equalsIgnoreCase("upload")) )
                    Hashtable files = mrequest.getFiles();
                    if ( (files != null) && (!files.isEmpty()) )
                        UploadFile file = (UploadFile) files.get("filename");
                        if (file != null)
                                            out.println("<li>Form field : uploadfile"+"<BR> Uploaded file : "+file.getFileName()+" ("+file.getFileSize()+" bytes)"+"<BR> Content Type : "+file.getContentType());
                                            String fileName=file.getFileName();
                                            String ran=System.currentTimeMillis()+"";
                                            String ext=fileName.substring(   ( fileName.length()-4),fileName.length() );
                                            file.setFileName(ran+ext);
                        // Uses the bean now to store specified by jsp:setProperty at the top.
                        upBean.store(mrequest, "filename");
                                            String title=request.getParameter("title");
                                            String content=request.getParameter("elm1");
                                            int x=dbc.addNews(title,content,file.getFileName(),2,1);
                                            if(x==1)
                                                     out.print("New Vedio has been addedd Successfully");
                                                      response.setHeader("Refresh","1;URL=uploadVedio.jsp");
                                                     else{
                                                      out.print("An Error Occured while adding new Vedio");
                                                      response.setHeader("Refresh","1;URL=uploadVedio.jsp");
                    else
                      out.println("<li>No uploaded files");
             else out.println("<BR> todo="+todo);
    %>
    <!-- end of add news-->
    <form action="" method="post" enctype="multipart/form-data" name="upform" >
      <table width="99%" border="0" align="center" cellpadding="1" cellspacing="1">
        <tr>
          <td colspan="2" align="right" bgcolor="#EAEAEA" class="borderdTable"><p>'6'A) .(1 ,/J/</p></td>
        </tr>
        <tr>
          <td width="87%" align="right"><label>
            <input name="title" type="text" class="rightText" id="title">
          </label></td>
          <td width="13%" align="right">9FH'F 'D.(1</td>
        </tr>
        <tr>
          <td align="right"><textarea name="elm1" cols="50" rows="10" id="elm1" style="direction:rtl" >
              </textarea></td>
          <td align="right">*A'5JD 'D.(1</td>
        </tr>
        <tr>
          <td align="right"><label>
            <input type="file" name="filename" id="filename">
          </label></td>
          <td align="right">5H1)</td>
        </tr>
        <tr>
          <td align="right"><label>
            <input onClick="submit()" name="addBTN" type="button" class="btn" id="addBTN" value="  '6'A) .(1 ">
          </label></td>
          <td align="right"> </td>
        </tr>
      </table>
    </form>
    <!-- TinyMCE -->
    <script type="text/javascript" src="jscripts/tiny_mce/tiny_mce.js"></script>
    <script type="text/javascript">
            tinyMCE.init({
                    mode : "textareas",
                    theme : "simple",
                    directionality : "rtl"
    </script>
    <!--end of TinyMCE -->

    the problem is not because of java code insdie jsp page
    I have removed all things but the form and it is still not working
    here is the modified code:
    <!-- add news-->
    <%
    if(request.getParameter("addBTN") != null){
            out.print("addBTN");
    %>
    <!-- end of add news-->
    <form action="" method="post" enctype="multipart/form-data" name="upform" >
      <table width="99%" border="0" align="center" cellpadding="1" cellspacing="1">
        <tr>
          <td colspan="2" align="right" bgcolor="#EAEAEA" class="borderdTable"><p>'6'A) .(1 ,/J/</p></td>
        </tr>
        <tr>
          <td width="87%" align="right"><label>
            <input name="title" type="text" class="rightText" id="title">
          </label></td>
          <td width="13%" align="right">9FH'F 'D.(1</td>
        </tr>
        <tr>
          <td align="right"><textarea name="elm1" cols="50" rows="10" id="elm1" style="direction:rtl" >
              </textarea></td>
          <td align="right">*A'5JD 'D.(1</td>
        </tr>
        <tr>
          <td align="right"><label>
            <input type="file" name="filename" id="filename">
          </label></td>
          <td align="right">5H1)</td>
        </tr>
        <tr>
          <td align="right"><label>
            <input name="addBTN" type="submit" class="btn" id="addBTN" value="  '6'A) .(1 ">
          </label></td>
          <td align="right"> </td>
        </tr>
      </table>
    </form>
    <!-- TinyMCE -->
    <script type="text/javascript" src="jscripts/tiny_mce/tiny_mce.js"></script>
    <script type="text/javascript">
            tinyMCE.init({
                    mode : "textareas",
                    theme : "simple",
                    directionality : "rtl"
    </script>
    <!--end of TinyMCE -->

  • Multipart/form-data and file attachment

    Hi ,
    This question has probably been asked before, but if not then here it is. Any replies will be appreciated:
    Q. When using "Enctype=Multipart/form-data", with file attachment alongwith other form fields, is it mandatory to attach a file ? What if user selects no file to attach?
    Q. If no, then how can it be possible that a form can be submitted without attaching a file since when I try to submit a form with no file attached to it, it gives me error message saying :java.lang.NullPointerException
    Q. Does it mean that I can't have a form with a blank "File" input field, if the form's Enctype is "multipart/form-data"? Since users may not select a file to attach to the form, in other words it is an optional.
    I hope I was clear enough in explaining my questions.
    Thanks in advance.

    I am using Orielly's file attachement pacakge.
    Here's what I am doing in my JSP page: It does the following:
    int maxFileSize = 10 * 1024 * 1024; // 5MB max
    String uploadDir = "/direct/files/upload/";
    String FormResults = "";
    String FileResults = "";
    String fileName = "";
    String fileName2 = "";
    String paramName="";
    String paramValue="";     
    File f;
    int filecounter=1;
    first get the form fields using following code:
    MultipartRequest multi = new MultipartRequest(request, uploadDir, maxFileSize);
    Enumeration params = multi.getParameterNames();
    //Get the form information
    while (params.hasMoreElements())
         paramName = (String) params.nextElement();     
         paramValue = multi.getParameter(paramName);
         if (paramName.equals("emailconfirm"))
              emailconfirmation = paramValue;
         else if (paramName.equals("Requester"))
              Requester = paramValue;
         else if (paramName.equals("TodaysDate"))
              TodaysDate = paramValue;
         else if (paramName.equals("Extension"))
    }//end while
    Then it gets the file information using the following code: I have two file fields in my form so that's why I am using a filecounter to find out if user has attached two files or just one:
    Enumeration files = multi.getFileNames();
    while (files.hasMoreElements())
         String formName = (String) files.nextElement();
         if (filecounter == 2)
    fileName2 = multi.getFilesystemName(formName);
         String fileType = multi.getContentType(formName);
              f = multi.getFile(formName);
         FileResults += "<BR>" + formName + "=" + fileName2 + ": Type= " + fileType + ":
    Size= " + f.length();
         else
         {     fileName = multi.getFilesystemName(formName);
              String fileType = multi.getContentType(formName);
              f = multi.getFile(formName);
              FileResults += "<BR>" + formName + "=" + fileName + ": Type= " + fileType + ":
    Size= " + f.length();
         filecounter=filecounter+1;
    Then after composing the mail message I send email with the form fields and file attachments using following code:
    Properties props = new Properties();
    MimeBodyPart mbp1 = new MimeBodyPart();
    MimeBodyPart mbp2 = new MimeBodyPart();
    MimeBodyPart mbp3 = new MimeBodyPart();
    URLDecoder urlDecoder = new URLDecoder();
    String to1 = urlDecoder.decode(toemail);
    String from1 = urlDecoder.decode(fromemail);
    String cc1 = urlDecoder.decode(ccemail);
    props.put( "mail.host", host );
    Session session1 = Session.getDefaultInstance(props, null);
    // Construct the message
    Message msg = new MimeMessage( session1 );
    msg.setFrom( new InternetAddress( from1 ) );
    msg.setRecipients( Message.RecipientType.TO, InternetAddress.parse( to1, false ) );
    msg.setRecipients( Message.RecipientType.CC, InternetAddress.parse( cc1, false ) );
    msg.setSubject( subject );
    msg.setHeader( "X-Mailer", "ExceptionErrorMail" );
    msg.setSentDate( new Date() );
    mbp1.setText(mail_message);
    mbp1.setContent(mail_message, "text/html");
    // Send the email message
    FileDataSource fds = new FileDataSource(uploadDir + fileName);
    FileDataSource fds2 = new FileDataSource(uploadDir + fileName2);
    mbp2.setDataHandler(new DataHandler(fds));
    mbp3.setDataHandler(new DataHandler(fds2));
    mbp2.setFileName(fileName);
    mbp3.setFileName(fileName2);
    Multipart mp = new MimeMultipart();
    mp.addBodyPart(mbp1);
    mp.addBodyPart(mbp2);
    mp.addBodyPart(mbp3);
    msg.setContent(mp);
    Transport.send( msg );
    //email sent...
    //delete the two files from the server..
    File f2 =new File(uploadDir + fileName);
    f2.delete();
    File f3 =new File(uploadDir + fileName2);
    f3.delete();     
    //End of code
    So when I don't attach a file and submit my form , I get the error message that I mentioned in my previous post.
    Any more ideas?

  • Difficulties in creating a JSP for File upload

    hello out there,
    im trying to create a ProcessUpload.jsp File which should handle a file upload from a channel in the portal. regarding a previously posted thread acording to fileupload i deployed this jsp-file in the regular webServerHierarchy so that you dont have to go into the desktopServlet Portal, which cant handle fileUpload.
    its location is this ../portal/test/ProcessUpload.jsp and it uses CustomTags referecens from /portal/WEB-INF/test.tld. i customized the deployment descriptor in /portal/WEB-INF/web.xml as well. but as soon as i try to put a taglib which uses this custom tags the server responses with an error.
    does anybody know how to deploy a global jsp file to handle file uploads, or something in particular how to deploy jsp with custom tags outside the desktopservlet but inside the portal webapp??
    i would be really thankful ;-)
    best regards
    martin

    hi alex,
    i allready tried to realize a channel with file upload download. channels are made up of jsp pages and when i am forwarding my form with enctype="multipart/form-data" encoding the desktop-servlet intercpets my entity-body.
    so what kind of channel you have thought about ??
    thanks for reply ;-)

Maybe you are looking for