我正在使用Liferay 6.1。 我的问题是,当我使用Liferay标签创建网址时,浏览器似乎无法正确确定文件名。 例如,使用<img>标签src属性中的以下URL会导致图像被命名为“images”,并且在保存文件时,新文件的名称为images.jpg而不是imageId123.jpg
http://example.com/images?p_p_id=imagesdisplay_WAR_imagesportlet&p_p_lifecycle=2&p_p_state=normal&p_p_mode=view&p_p_cacheability=cacheLevelPage&_imagesdisplay_WAR_imagesportlet_struts.portlet.action=%2Fview%2FgetWmarkedImage&imageId=imageId123
我需要将图像名称设置为imageId123,因此当它保存时,它将具有文件名,例如imageId123.jpg。 当图像保存在计算机上时,有没有办法指定图像名称或下载的文件名?
I'm using Liferay 6.1. My problem is that when I create a url using Liferay tags the browser does not seem to be able to determine the filename correctly. For example using the below url in the <img> tag src attribute results in the image being named "images" and when the file is saved the new file's name is images.jpg instead of imageId123.jpg
http://example.com/images?p_p_id=imagesdisplay_WAR_imagesportlet&p_p_lifecycle=2&p_p_state=normal&p_p_mode=view&p_p_cacheability=cacheLevelPage&_imagesdisplay_WAR_imagesportlet_struts.portlet.action=%2Fview%2FgetWmarkedImage&imageId=imageId123
I need the image name to be imageId123 so when it's saved it will have a file name such as imageId123.jpg. Is there a way to specify the image name or the downloaded file name when the image is saved on the computer?
最满意答案
你不应该通过download-filename来做。
请改用content-disposition标头。
responseFile.setContentType("application/x-download"); responseFile.setHeader("Content-disposition", "attachment; filename=imageId123");You shall not do it via the download-filename.
Use content-disposition header instead.
responseFile.setContentType("application/x-download"); responseFile.setHeader("Content-disposition", "attachment; filename=imageId123");更多推荐
发布评论