forked from neil/plugin-external-background
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
45 lines
1.4 KiB
45 lines
1.4 KiB
package com.fr.plugin.external.web; |
|
|
|
import com.fr.data.NetworkHelper; |
|
import com.fr.general.IOUtils; |
|
import com.fr.general.xml.GeneralXMLTools; |
|
import com.fr.plugin.external.ImageManager; |
|
import com.fr.stable.fun.impl.AbstractRequestInterceptor; |
|
|
|
import javax.servlet.http.HttpServletRequest; |
|
import javax.servlet.http.HttpServletResponse; |
|
import java.awt.*; |
|
import java.io.ByteArrayInputStream; |
|
import java.io.OutputStream; |
|
|
|
public class DownloadImageAction extends AbstractRequestInterceptor { |
|
@Override |
|
public String getCMD() { |
|
return "download"; |
|
} |
|
|
|
@Override |
|
public void actionCMD(HttpServletRequest req, HttpServletResponse res) throws Exception { |
|
actionCMD(req, res, null); |
|
} |
|
|
|
@Override |
|
public void actionCMD(HttpServletRequest req, HttpServletResponse res, String sessionID) throws Exception { |
|
String id = NetworkHelper.getHTTPRequestParameter(req, "imageid"); |
|
Image image = ImageManager.getInstance().findImageById(id); |
|
|
|
if (image == null) { |
|
return; |
|
} |
|
String disposition = "attachment; filename=" + id + ".png"; |
|
res.setContentType("image/png"); |
|
res.setHeader("extension", "png"); |
|
res.setHeader("Content-disposition", disposition); |
|
|
|
byte[] content = GeneralXMLTools.imageEncode(image); |
|
OutputStream out = res.getOutputStream(); |
|
IOUtils.copyBinaryTo(new ByteArrayInputStream(content), out); |
|
out.close(); |
|
|
|
} |
|
}
|
|
|