wood burning stoves
The moose likes JSF and the fly likes How to download file throuch datahandler object? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

JavaRanch » Java Forums » Java » JSF
Bookmark "How to download file throuch datahandler object?" Watch "How to download file throuch datahandler object?" New topic

How to download file throuch datahandler object?

Kush Sahu

Joined: Jan 08, 2013
Posts: 1
I want to download a file in my jsf project. At bean side I am getting object of DataHandler. I tried to search many times but I did not found anything related to it. How can I download a file through datahandler object?

DataHandler src = attachment.getAttachment();

ByteArrayOutputStream output = new ByteArrayOutputStream();
FacesContext facesContext = FacesContext.getCurrentInstance();
ExternalContext externalContext = facesContext.getExternalContext();
externalContext.setResponseHeader("Content-Type", src.getContentType());
externalContext.setResponseHeader("Content-Disposition", "attachment;filename=sachin.jpg");

And if anybody knows about a good tutorial on file download and file upload which describes whole process in detail would be great for me.
Volodymyr Lysenko
Ranch Hand

Joined: Mar 29, 2012
Posts: 511

I know good tutorial on uploading files. It works for me

True person is moral, false is right!
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
subject: How to download file throuch datahandler object?
It's not a secret anymore!