Using apache FileUpLoad?

Hello
I am to trying write a small web application which allows the user to upload files to there account.
And rather than storing them on a database, to store the files on the server and a link to the file on the database.
I have seen examples how to obtain the files using the apache FileUpLoad tool. But wondered if anyone could advise, how to store the files on the server.
So each file has a unique filename, and stop new files from writing over existing stored files. Is there are some way I could name them on the server as File1, File2 File3.... and keep a record of the current number?
Thanks

Use java.io.FileOutputStream to store them in a common directory.
- Saish

Similar Messages

  • Help in mutlipart post FIle Upload using Apache FileUpload

    Hi there,
    I am using the FileUpload class of Apache and getting an issue when I try to write the multipart post data (file) into a physical disk on the server. I am attaching herewith the servlet code. The error I get when I compile the code is:
    Information: 1 error
    Information: 0 warnings
    Information: Compilation completed with 1 errors and 0 warnings
    C:\unzipped\commons-fileupload-1.0-src\commons-fileupload-1.0\src\java\FileUpload.java
    Error: line (80) write(java.io.File) in org.apache.commons.fileupload.FileItem cannot be applied to (java.lang.String)
    C:/unzipped/commons-fileupload-1.0-src/commons-fileupload-1.0/src/java/FileUpload.java:80: write(java.io.File) in org.apache.commons.fileupload.FileItem cannot be applied to (java.lang.String)
    Any help would be greatly appreciated.
    Thanks
    John

    are you calling the writeFile method trying to pass a String instead of a File object?

  • File upload using apache Commons FileUpload problem

    Hi All,
    I have used Commons FileUpload for uploading files from windows to unix machine. I'm able to upload files but I have a problem about the contents of file copied in unix. When i upload files few files containing special characters are not copied correctly in unix instead ascii codes are getting copied/written. Seems to be a problem with character encoding.
    For example symbol "�" is not getting copied correctly in unix. So as new line character to. If anyone has faced such issues kindly provide few pointers on this. Appreciate your guidance.
    Thanks,
    -Aj

    Thanks for the reply.
    I'm using the Commons FileUpload class "FileItem" which holds the filestream data and using function
    code snippet of file upload
    ServletFileUpload servletFileUpload = new ServletFileUpload(new DiskFileItemFactory());
    List fileItemsList = servletFileUpload.parseRequest(request);
    Iterator it = fileItemsList.iterator();
    while (it.hasNext())
         FileItem fileItemTemp = (FileItem)it.next();
         File saveToFile = new File("newFile");
          fileItem.write(saveToFile ); // write fileItem data to saveToFile.
    } FileItem object takes care of writing data to disk.No idea,how it does internally.
    Thanks,
    -Aj.

  • Apache FileUpload - what version of Tomcat can run it?

    Hi. I'm trying to use the Apache Commons FileUpload component (http://commons.apache.org/fileupload). It works fine on my local PC (Java 1.5.0_15) but fails on the Unix server running Tomcat 4.1.29 and Java 1.4.2_12-b03. I've got the latest version of the upload component in the WEB-INF/lib folder. It throws this error (included only the top section; there are more, similar errors having to do with each fileupload component call). Do I need an older version of the upload component to work with this version of Tomcat and Java? If so, which version do I need to download? The oldest I could find dated to 2003. Thanks.
    The server encountered an internal error () that prevented it from fulfilling this request.
    org.apache.jasper.JasperException: Unable to compile class for JSP
    An error occurred at line: 15 in the jsp file: /fpauto/viewPremiums.jsp
    Generated servlet error:
    [javac] Compiling 1 source file
    /usr/local/jakarta-tomcat-4.1.29/work/mywork/fpauto/viewPremiums_jsp.java:12: package org.apache.commons.fileupload does not exist
    import org.apache.commons.fileupload.FileItem;
    ^/usr/local/jakarta-tomcat-4.1.29/work/mywork/fpauto/viewPremiums_jsp.java:14: package org.apache.commons.fileupload.servlet does not exist^
    ^import org.apache.commons.fileupload.servlet.ServletFileUpload;^
    /usr/local/jakarta-tomcat-4.1.29/work/mywork/fpauto/viewPremiums_jsp.java:15: package org.apache.commons.fileupload.disk does not exist
    import org.apache.commons.fileupload.disk.DiskFileItemFactory;
    ^/usr/local/jakarta-tomcat-4.1.29/work/mywork/fpauto/viewPremiums_jsp.java:16: package org.apache.commons.fileupload does not exist^
    ^import org.apache.commons.fileupload.FileUpload;^
    /usr/local/jakarta-tomcat-4.1.29/work/mywork/fpauto/viewPremiums_jsp.java:74: cannot resolve symbol
    symbol : class DiskFileItemFactory
    location: class org.apache.jsp.viewPremiums_jsp
    DiskFileItemFactory factory = new DiskFileItemFactory();
    An error occurred at line: 15 in the jsp file: /fpauto/viewPremiums.jsp
    Generated servlet error:
    /usr/local/jakarta-tomcat-4.1.29/work/mywork/fpauto/viewPremiums_jsp.java:74: cannot resolve symbol
    symbol : class DiskFileItemFactory
    location: class org.apache.jsp.viewPremiums_jsp
    DiskFileItemFactory factory = new DiskFileItemFactory();

    Apache FileUpload - what version of Tomcat can run it?First of all, why don't you ask Apache specific questions at the Apache mailinglist?
    Regarding to your actual problem: those are just ordinary compilation errors which are complaining that the mentioned packages and classes aren't available in the classpath. The solution is obvious: add the mentioned packages and classes (or in this case, the JAR file(s) with it) to the classpath during compile time and you're fine.

  • Can't use Jakarta FileUpload in JSF?

    I am trying to use Jakarta FileUpload for uploading a file to server database. It works fine in JSP. However, when I migrate the system to JSF, it does not work again. I can find that the request type seems that is different. In JSP, the request received by Servlet is SRTServletRequest. In JSF, it is MultiPartExternalContextImpl$MultiPartServletRequestWrapper.
    When I trace the fileupload class in JSF, the jakarta fileupload cannot parse the request to List object and finally, fail to get the file(s).
    My question is, can I parse the "JSF request" to get the file(s)? If not, how can I change the request type?
    I know that there is a fileupload package in JSF, however, can it upload the file by inputstream (memory in server) only, rather than need to upload the file at a server (second storage in server) first?
    Thanks for any reply.

    I use file upload of myFaces extensions with Sun JSF RI.
    I did the following steps:
    1) Added: Tomahawk.jar to "lib" folder.
    2) Added myFaces apache filter to "web.xml". Take a look here: http://myfaces.apache.org/tomahawk/extensionsFilter.html.
    3) Added upload field to the form:
    for example:
    <t:inputFileUpload
    id="themeFile"
    value="#{themeBean.themeFile}"
    storage="file"
    required="true"
    validator="#{themeBean.validateThemeFileName}"
    style="width:100%" />
    4) Add to your Bean the following member (with setter and getter):
    private UploadedFile themeFile;
    5) On the "save" action of the form add the following code in order to extract the uploaded file:
    InputStream in = new BufferedInputStream(
    themeFile.getInputStream()); // This is the uploaded file
    BufferedOutputStream os =
    new BufferedOutputStream(new FileOutputStream(newFile)); // newFile is the file you would like to store on the server
    byte[] data = new byte[BUFFER_SIZE];
    int readSize;
    while ((readSize = in.read(data, 0, BUFFER_SIZE)) != -1)
    os.write(data, 0, readSize);
    in.close();
    os.close();
    Hope it helps . . .

  • Problem in upload PDF file using Apache HttpClient3.1

    Hi:
    I am using Apache HttpClient 3.1 to upload pdf image from a STANDALONE java application to remote server (Weblogic9.1). Here are some questions:
    1) Do i have to use multipartpost method? (I am uploading pdf image one by one)
    2) The pdf image is added to request as:
    HttpClient client = new HttpClient();
    PostMethod method = new PostMethod("myServletUrl");
    method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,
    new DefaultHttpMethodRetryHandler(3, false));
    InputStreamRequestEntity entity = new InputStreamRequestEntity(new FileInputStream(file), "application/pdf");
    method.setRequestEntity(entity);
    method.setRequestHeader("Content-type", entity.getContentType());
    int statusCode = client.executeMethod(method);
    3) On server side, a servlet will save the posted pdf image as (Apache FileUpload is not used here):
    InputStream is = req.getInputStream();
    saveFile(is, fileName); // write this input stream to file.
    The above steps 2 and 3 will create a pdf file on remote server with MUCH REDUCED size. Any idea what's the problem? content-type problem?
    4) An working example link will be great.
    thanks

    Dunno, but as this is a client side issue, the solution, if there is one will lie in the HTML / javaScript.
    If you dont get an answer in here, have google for an HTML solution, which you can then write out in your jsp.

  • SSO with a website using Apache Httpclient form post

    Hi ,
    I am trying to obtain, SS0 with a website, that accepts the user information via post.
    I tried using app Integrator, but the website sends a cookie in first request, and redirects to another URL. App Integrator is only catching the first response.
    Thus i tried implementing this Form post using Apache HTTPClient class inside the Abstractportacomponent, as shown..
    The login is taking place. But, When i click on any link on the page, It is redirecting to the login page again, I am wondering where should i give the Cookie, so the portal request will include that cookie in its subsequent requests, so that i wont be prompted for login agian..
    thank you,
    chiranjeevi.
    public void doContent(IPortalComponentRequest request, IPortalComponentResponse response)
        {try
                      String url = "http://www.xxxxxxxxxxxxx.com/gold_online/validate.asp";
                      //Here, calling the timberline comes into place.
                       HttpClient client = new HttpClient();
                        PostMethod method = new PostMethod (url);
                        method.setFollowRedirects(false);
                        method.addParameter( "code","xxxxxxx");
                        method.addParameter( "upass", "xxxxxx" );
                                  int statusCode = client.executeMethod( method );
                        if( statusCode != -1 ) {
                             // The Status code for this first request is 302..which is a redirect with the redirect path
                             Header locationHeader = method.getResponseHeader("location");
                             Header cookie = method.getResponseHeader("set-cookie");
                             String redirectedURL = locationHeader.getValue();
                             String host = "http://www.xxxxxxxxxxxxxx.com/gold_online/";
                             redirectedURL = host+redirectedURL;
                             GetMethod method2 = new GetMethod (redirectedURL);
                             method2.setFollowRedirects(false);
                             method2.setRequestHeader("cookie",cookie.getValue());
                             method2.addRequestHeader("Accept", "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, /");
                             int statuscode2 = client.executeMethod( method2);
                             String contents  = method2.getResponseBodyAsString();
                             // Converting the Relative URLs to Absolute URLs
                             contents = replace (contents,"src=\"","src=\""+host);
                             contents = replace(contents,"href=\"","href=\""+ host);
                             Cookie ck = new Cookie("cookie", cookie.getValue()) ;
                             //adding the cookie to the response...
                             response.addCookie(ck);
                             response.write(contents);
                          method.releaseConnection();

    Hi Manish,
    first, welcome on SDN! About your question:
    The URL iView in SP9++ has been reported quite instable from different sides (just do a look on "URL iView" within this forum). The alternative for the aim you have is to use the good "old" application integrator iView, which behaves very stable and will do what you want without hesitating...
    Also see URL iView and HTTP System - SSO to web app
    Hope it helps
    Detlev
    PS: Please consider to reward point for helpful answers on SDN. Thanks in advance!

  • Maximum file size using htmlb:fileUpload

    Hello Gurus,
    in a bsp application we are using htmlb:fileUpload. It was possible to upload a 43 MB file without problem. But our maximum file size is about 220 MB. We made a test with a 190 MB file. After we hit the post button, the browser disconnects immediately (without timedelay) with the message: page cannot be displayed.
    for me it looks like we hit some restriction.
    any idears how to manage the 220 MB file in the browser beside splitting it into smaller files would be greatly appreciated.
    thx a lot in advance and regards from
    Michael

    Hello again,
    could it be this parameter which is for the limitation responsible ?
    icm/HTTP/max_request_size_KB   = 102400
    thx and best regards from Michael

  • PDF Creation and Saving in Database using Apache FOP

    Hi,
    I read lot of topics in this forum about using Apache FOP for creating PDF documents and I have configured the same and works fine.
    When user clicks a button, the PDF file is generated and it downloads the document. How can I make the PDF document save in the database.
    I would like to provide a interactive report with a link and they can download the document later.
    Thanks
    Karthik

    Hi, Karthik
    Think here how to save pdf in APEX 3.0 you can find more information about this
    Michael

  • Chinese Charcters in PDF using Apache FOP

    Hi,
    I am creating a PDF using Apache FOP.
    This data contains Chinese characters.
    On APEX 3.1, I couldn't contain Chinese characters in PDF.
    On APEX 3.2, is it possible?
    Is there any way that I don't have to use BI Publisher?
    Please advise on this.
    Thanks

    Hi, Karthik
    Think here how to save pdf in APEX 3.0 you can find more information about this
    Michael

  • Providing security to the PDF file using apache FOP in java

    I am working on PDF file generation using Apache FOP, I have security concerns which are
    1. PDF file will be placed in a folder after generation and that should not be copied to other locations.
    2. PDF file should only have an option print nothing else. The save/save as options should never be enabled.
    3. PDF expiry date is required, so that PDF file will get expire after duration.

    HI,
    I did that too, with too much experiments.
    Code snippet for reference.
    PdfReader reader = new PdfReader(getOutputFilePath());
    PdfStamper stamper = new PdfStamper(reader, new FileOutputStream("my-new-file.pdf"));
    stamper.setDuration(1,1);
    int permissions = PdfWriter.HideMenubar & PdfWriter.HideToolbar & PdfWriter.HideWindowUI & ~( PdfWriter.AllowCopy | PdfWriter.AllowModifyAnnotations | PdfWriter.AllowFillIn | PdfWriter.AllowAssembly | PdfWriter.AllowModifyContents | PdfWriter.AllowScreenReaders);
    stamper.setEncryption(null, null,
    permissions, PdfWriter.STRENGTH40BITS);
    stamper.setFormFlattening(true);
    System.out.println(stamper.getMoreInfo());
    stamper.close();
    I am able to disable the save button, but I am unable to disable the save as option.
    It would be great help, if you can give some inputs on this.

  • Enterprise portal access using reverse proxy using Apache and webdispatcher

    Hi Guys,
    As requirement, we need to give solution to customer about Reverse proxy scenario. I am new to this part.
    What we have think of to use Apache and Web dispatcher.
    I tried to search documents and found some sdn links also but still i am not comfortable to go about.
    Need suggestion and document if anyone has used so far.reverse proxy.
    As basis person, we need to do all ( Apache installation, Apache configuration, Web dispatcher installation and configuration, integration with EP.)
    It will helpful to me if i can get Apache installation, Apache configuration part and integration with EP, or web dispatcher, configuration etc.
    Thanks,
    Deepak

    We used Netscaler for Reverse Proxy implementation and can assure you that network team performed most of the set ups. This was on EP 7.01.
    From BASIS stand point it would be primarily Web Dispatcher Configuration.
    Also refer the links I specified in another thread. There are several scenarios discussed there -
    Re: Post values for userid and passowrd fields in logon page
    http://wiki.sdn.sap.com/wiki/display/BSP/Using+Proxies
    ~ Dhanz

  • Obtaining client certificate in servlet using apache + tomcat

    Hi,
    I'm porting a webapplication from Javawebserver to Apache/1.3.6 (Win32) mod_jk mod_ssl/2.2.6 OpenSSL/0.9.2b
    The application needs to get the client certificate hash code.
    Using Javawebserver I used
    request.getAttribute ("javax.net.ssl.cipher_suite");
    request.getAttribute("javax.net.ssl.peer_certificates");
    etc
    How do I set up the apache webserver so that I can read the client certificate and what is the attribute called?
    I've tried this in the httpd.conf:
    SSLOptions +ExportCertData
    And the attribute:
    "SSL_CLIENT_CERT"
    Like it says in the Tomcat documentation.
    I'm not sure if I need to set up Tomcat as well..
    Any help would be greatly appriciated!
    Sincerely,
    AM Hjemaas

    Yup use ajp13 not ajp12 or mod_webapp
    refer to http://www.galatea.com/flashguides/apache-tomcat-24-win32.xml on setting up..
    THIS IS IMPORTANT!!!
    use Apache mod_jk.dll diretive:
    JkEnvVar Apache_Env_Var FORWARD_ALIAS
    this will send a apache environment variable (http://myapache/cgi-bin/printenv.pl to see whats available) to Tomcat
    JkEnvVar SSL_CLIENT_CERT SSL_CLIENT_CERT
    Then in Tomcat servlet use request.getAttribute("SSL_CLIENT_CERT") to get the cert in PEM format
    Hope this helps
    Jay

  • Problems with SSL using Apache proxy

    I'm trying to use Apache+mod_ssl+openssl on linux RedHat 6.2 and mod_wl_ssl from WLS 5.1+SP5. Setting PathTrim in httpd.conf I'm able to send http request
    to WebLogic Cluster located on outside machines. However, https requests don't work and I receive the following messages in httpd's error_log
    [Fri Sep 1 13:44:01 2000] [notice] Apache/1.3.12 (Unix) mod_ssl/2.6.6 OpenSSL/0.9.5a configured -- resuming normal operations
    [Fri Sep 1 13:44:28 2000] [notice] child pid 12329 exit signal Segmentation fault (11) Do you receive the same message in error_log
    Any help you can provide will be appreciated.
    Enrico

    My client (Netscape browser) are making SSL connection to Apache.
    I would use SSL3 from client to Apache then read the client certificate from
    WebLogic (in back-end) servlet to check the user's attribute from ldap
    server. Could you tell me if there is some example of keeping client
    certificate from front-end web server to WebLogic servlet?
    Thanks,
    Enrico
    Michael Girdley <[email protected]> wrote in message
    [email protected]..
    >
    >
    You're making SSL connections from Apache to WebLogic? Or your clientsare
    making SSL connections to Apache?
    Thanks,
    Michael
    Michael Girdley
    BEA Systems Inc
    "enrico notariale" <[email protected]> wrote in message
    news:39b5fa6f$[email protected]..
    I'm trying to use Apache+mod_ssl+openssl on linux RedHat 6.2 andmod_wl_ssl from WLS 5.1+SP5. Setting PathTrim in httpd.conf I'm able tosend
    http request
    to WebLogic Cluster located on outside machines. However, https
    requests
    don't work and I receive the following messages in httpd's error_log
    [Fri Sep 1 13:44:01 2000] [notice] Apache/1.3.12 (Unix) mod_ssl/2.6.6OpenSSL/0.9.5a configured -- resuming normal operations
    [Fri Sep 1 13:44:28 2000] [notice] child pid 12329 exit signalSegmentation fault (11) Do you receive the same message in error_log
    Any help you can provide will be appreciated.
    Enrico

  • How to create an instance using apache bean utils

    Hi All,
    I am new to java forums....
    can you help me..
    i have to use apache bean for setting and getting the methods using java bean..
    somewhere i have to use BasicDynaBean and BasicDynaClass..
    can you help me in proceeding...
    Thanks in advance....
    :)

    This forum is meant for general Java questions. Your question is better asked on a Apache mailing list:
    [http://commons.apache.org/beanutils/mail-lists.html]
    But before posting there, I suggest you first read u[p on how to ask a question on a public forum or mailing list, because if you post what you now just posted here on a mailing list, I doubt that you'll get answered.
    [http://www.catb.org/~esr/faqs/smart-questions.html]
    Good luck.

Maybe you are looking for

  • Video plays fine in iMovie but is messed up on DVD?

    I made a 15-minute video using iMovie. I then made a DVD using iDVD; however, about 5 minutes in on the DVD, stuff gets weird. There are clips where I muted the video and had a voiceover, but for some reason on the DVD you can still hear the audio fr

  • HT201272 How can I get my old ringtones back

    Hi I have the new I phone 5s but I used to have I phone 4  . when I had my old phone I purchased a lot of ringtones .is there a way that I can get my ringtones back and if it is can someone please help me? And thanks in advance .

  • AP PHY data rates

    Hello, AP 1600 has PHY data rates up to 300 Mbps, and 2600 up to 450 Mbps. With 1600 AP, if I have a client connected at 300 Mbps on the radio 5 GHz (MCS index 15, 40 Mhz) and another client connected at 130 Mbps on the radio 2.4 GHz at 130 Mbps (MCS

  • How to read cluster data

    How can I read in separate paramters from a cluster? (plz see the attached VI) It could be a simple problem, but I cannot figure this out. plz help! BR, Attachments: aggressor config read.vi ‏57 KB

  • Wireless and USB keyboard dosen´t work during boot

    After rebooting my Imac the keyboard dosen´t respond in the boot phase. I get this famous blinking question mark at booting so I have to press C or D on the keyboard for options. The problem is that neither the wireless keyboard or my new USB keyboar