-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Loading Uploaded File is taking too long
PostPosted: Tue May 04, 2010 11:55 am 
Newbie

Joined: Mon Jun 01, 2009 10:53 am
Posts: 6
Hello there,

I'm using hibernate in my project, this project allow users to upload file to the server and these files are being saved on the database. This is working just fine, but when I try to download a file it takes too long to load from the database and start the download. What I do to send the file to the user is use a servlet to load this file from the database and write to the output stream.

This is my servlet that sends the file:
Code:
public class Arqs extends HttpServlet {
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        String id = request.getParameter("id");
        Arquivo arq = ArquivoJPA.recuperar(Long.parseLong(id));

        System.out.println(arq.getId());
        System.out.println(arq.getNome());
        System.out.println(arq.getEnctype());

        response.setContentType(arq.getEnctype());
        response.setHeader("Content-Disposition", "attachment; filename=\"" + arq.getNome() + "\"");
        response.getOutputStream().write(arq.getArquivo());
    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        processRequest(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        processRequest(request, response);
    }
}


And this is my Entity File:
Code:
@Inheritance(strategy=InheritanceType.TABLE_PER_CLASS)
public abstract class Arquivo implements Serializable {
    @TableGenerator(name="arquivo_geradorid", table="arquivo_geradorid", allocationSize=1)
    @Id
    @GeneratedValue(strategy = GenerationType.TABLE, generator="arquivo_geradorid")
    private Long id;
    private String nome;
    private String enctype;
    private String extensao;
    @Column(length=33554432)
    private byte[] arquivo;

... getters and setters
}


Is there anyway to make this loading faster? I mean I know that the problem is that is taking too long to load, because for a file of 2 megabytes it takes around 20 seconds to load and then it gives me the option to save or open.

Thanks in advance,
Bruno Krebs.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.