从动态创建的URL确定图像名称(Determine image name from dynamically created URL)

编程入门 行业动态 更新时间:2024-10-27 04:31:38
从动态创建的URL确定图像名称(Determine image name from dynamically created URL) java

我正在使用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");

更多推荐

本文发布于:2023-08-07 10:56:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1464187.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:图像   名称   动态   URL   created

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!