Quando eu recupero o arquivo do banco de dados, ele está me retornando no formato application/octet-stream, só que esse arquivo é um .doc.
Eu gostaria de salvar esse arquivo no meu computador mas ele está perdendo o type dele.
e quando está salvando ele está colocando um nome estranho também
Preciso de ajuda urgente fazem três dias que estou empacado.
Existe um outro problema estou utilizando PORTLET
response.setHeader("Content-Disposition", "attachment;filename=" + anexo.getName());
response.setContentType(anexo.getType());
response.setContentLength(anexo.getArquivo().length);
response.getOutputStream().write(anexo.getArquivo());
response.getOutputStream().flush();
response.getOutputStream().close();
Já tentou utilizar um destes mime types?
application/msword
application/doc
appl/text
application/vnd.msword
application/vnd.ms-word
application/winword
application/word
application/x-msw6
application/x-msword
zz-application/zz-winassoc-doc
O que está sendo retornando aqui: anexo.getType() e aqui: anexo.getName() ?
Eu criei um servlet a parte do Portlet e funcionou numa boa.
Fiz o mapeamento no web.xml do servlet e criei a classe.
O unico problema que eu tive que instaciar o spring na mão.
[code]public class DownloadFileAction extends HttpServlet
{
private static final Logger logger = Logger.getLogger(DownloadFileAction.class.getName());
private ServletContext context;
private AnexoService anexoService;
@Override
public void init(ServletConfig config) throws ServletException
{
this.context = config.getServletContext();
ApplicationContext springContext = WebApplicationContextUtils.getWebApplicationContext(this.context);
this.anexoService = (AnexoService) springContext.getBean("anexoService");
super.init(config);
}
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
logger.fine("Processando o plain file renderer servlet.");
Anexo anexo;
try
{
anexo = this.anexoService.getAnexo(request.getParameter("id"));
response.setHeader("Content-Disposition", "attachment;filename=" + anexo.getName());
response.setContentType(anexo.getType());
response.setContentLength(anexo.getArquivo().length);
response.getOutputStream().write(anexo.getArquivo());
response.getOutputStream().flush();
response.getOutputStream().close();
}
catch (Exception e)
{
logger.warning("Erro ao recuperar o arquivo.");
response.sendError(HttpServletResponse.SC_NOT_FOUND);
}
}
private static final long serialVersionUID = 1L;
}[/code]