commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jaime Martín <>
Subject problem uploading pdf file
Date Thu, 03 Dec 2009 17:42:47 GMT
I´m using FileUpload 1.2.1 I want to upload a pdf file. As a first 
approach I want to achieve this:
I have a file C:/firm-jmp.pdf and I want to upload it to 

On the one hand I invoke the servlet this way:

    public String saveFile()
        String fileName ="";
            fileName = "firm-jmp.pdf";
            String nombreFichero ="C:/".concat(fileName);

            URL url = new URL("http://localhost:8080/FondvalCNMV/upload");
            URLConnection con = url.openConnection();
             // inform the connection that we will send output and 
accept input

           // Don't use a cached version of URL connection.
           con.setUseCaches (false);
           con.setDefaultUseCaches (false);

           // define a new PrintWriter on the output stream
           PrintWriter outWriter = new PrintWriter(con.getOutputStream());

           // send data to the servlet
           InputStream input = con.getInputStream();
           File outputFile = new File(fileName);
           FileOutputStream out = new FileOutputStream(outputFile);

           boolean eof = false;
           // read all bytes from the input and write them to the output
           while (!eof) {
               // read  the stream
             int byteValue =;
             if (byteValue  == -1)
               eof = true;
        }catch (Exception e) {
            fileName ="";
        return fileName;

On the other hand this is my servlet´s doPost.

    protected void doPost(HttpServletRequest request, 
HttpServletResponse response)
    throws ServletException, IOException {
        String nomFichero ="";
        if (request.getParameter("firmaApoderado") != null) {
            nomFichero = request.getParameter("firmaApoderado");
        boolean isMultipart = ServletFileUpload.isMultipartContent(request);
        if(isMultipart) {
            // Create a factory for disk-based file items
            DiskFileItemFactory factory = new DiskFileItemFactory();
            // Set factory constraints
            File ff = new File("C:/firma-jmp.pdf");
            // Create a new file upload handler
            ServletFileUpload upload = new ServletFileUpload(factory);
            // Set overall request size constraint
       // Parse the request
            List<FileItem> items;
            try {
                items = upload.parseRequest(request);

            for(FileItem item : items) {
            if (item.isFormField()) {
                String name = item.getFieldName();
                String value = item.getString();
                System.out.println("name "+name);
                System.out.println("value "+value);
                String uploadFileName="D:/test/"+name ;
                File f = new File(uploadFileName);
            catch (FileUploadException e) {
            catch (Exception e) {


I have no error, the matter is that items = 
upload.parseRequest(request); turns out to return no items, it seems 
that I receive no file in the request.
I guess I´m doing something wrong as for my invocation.
thanks in advance!

Este mensaje de correo electrónico y sus documentos adjuntos están dirigidos
exclusivamente a los destinatarios especificados. Puede contener información
confidencial o legalmente protegida. No hay renuncia a la confidencialidad o
privilegio por cualquier transmisión errónea. Si usted no es el destinatario
indicado, le rogamos que lo elimine y se lo comunique al remitente. No debe,
directa o indirectamente, usar, revelar, distribuir, imprimir o copiar 
ninguna de las partes de este mensaje. Si siendo destinatario de este 
mensaje no consintiera el uso de correo electrónico, rogamos nos lo 
comunique inmediatamente.
RBCDexia Investor Services E,S.A. y sus filiales no serán responsables de las
opiniones o informaciones incluidas en este mensaje salvo cuando el remitente esté 
autorizado para establecer que dichas opiniones proceden de RBCDexia Investor
Services ,S.A.  y sus filiales.

Addressee/s identified herein. It may contain confidential or legally 
privileged information. No confidentiality privilege is waived or lost
by any mistransmission. If you are not the intended recipient, please
immediately delete it and notify the sender. You must not, directly or
indirectly, disclose, distribute, print, or copy any part of this message.
If you are the addressee of this message and do not consent to the use of
e-mail, please communicate it to us immediately. RBCDexia Investor Services
S.A. and its subsidiaries are not responsible for the opinions or information
included in this message except when the sender is authorised to state them to
 be the views of RBCDexia Investor Services, S.A. and its subsidiaries.

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message