Image 在服务器之间传递映像以进行远程保存
我的Spring应用程序将图像文件传递给Jersey应用程序,以摆脱所有图像处理任务 在接收图像时,Jersey应用程序应在多次操作(裁剪、调整大小等)后保存图像,并返回图像url 为此,Spring应用程序在JSP文件中具有以下表单:Image 在服务器之间传递映像以进行远程保存,image,spring,file,jersey,Image,Spring,File,Jersey,我的Spring应用程序将图像文件传递给Jersey应用程序,以摆脱所有图像处理任务 在接收图像时,Jersey应用程序应在多次操作(裁剪、调整大小等)后保存图像,并返回图像url 为此,Spring应用程序在JSP文件中具有以下表单: <form method="POST" action="/asdf" enctype="multipart/form-data"> <input type="file" name="fstream"></input>
<form method="POST" action="/asdf" enctype="multipart/form-data">
<input type="file" name="fstream"></input>
<input type="submit" value="Upload"/>
</form>
执行上述预期行动的简单方法是什么?
如何在Spring应用程序中将其转换为BuffereImage,将其发布到Jersey应用程序,执行所需操作并保存图像
如果可以,如何将DataInputStream转换为BuffereImage
提前谢谢。因为没有答案
@PUT
@Path("upload/{fileName}")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response upload(@PathParam("fileName") String fileName, FileBytes fileBytes){
byte[] bytearray = fileBytes.getFileBytes();
int len = bytearray.length;
if(len>0){
try {
int width=0, height=0, edge=0, px1=0, px2=0;
InputStream in = new ByteArrayInputStream(bytearray);
BufferedImage image = ImageIO.read(in);
File file = new File(Constants.PATH_TO_IMAGES+Constants.PATH_ORIGINAL+fileName+".jpg");
ImageIO.write(image, "png", file); //saving original image
width = image.getWidth();
height = image.getHeight();
//scaling as required
if(height>width){
px2 = (height-width)/2+1;
edge = width;
}else if(width>height){
px1 = (width-height)/2+1;
edge = height;
}else{
edge = width;
}
//using ImgScalr API to get scaled image
image = image.getSubimage(px1, px2, edge, edge);
image = Scalr.resize(image, 120);
file = new File(Constants.PATH_TO_IMAGES+Constants.PATH_THUMBNAIL+fileName+".jpg");
ImageIO.write(image, "png", file); //saving scaled image
} catch (Exception e) {
e.printStackTrace();
}
}
return Response.status(Status.OK).entity("Filename:"+fileName).build();
}
}
@PUT
@Path("upload/{fileName}")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response upload(@PathParam("fileName") String fileName, FileBytes fileBytes){
byte[] bytearray = fileBytes.getFileBytes();
int len = bytearray.length;
if(len>0){
try {
int width=0, height=0, edge=0, px1=0, px2=0;
InputStream in = new ByteArrayInputStream(bytearray);
BufferedImage image = ImageIO.read(in);
File file = new File(Constants.PATH_TO_IMAGES+Constants.PATH_ORIGINAL+fileName+".jpg");
ImageIO.write(image, "png", file); //saving original image
width = image.getWidth();
height = image.getHeight();
//scaling as required
if(height>width){
px2 = (height-width)/2+1;
edge = width;
}else if(width>height){
px1 = (width-height)/2+1;
edge = height;
}else{
edge = width;
}
//using ImgScalr API to get scaled image
image = image.getSubimage(px1, px2, edge, edge);
image = Scalr.resize(image, 120);
file = new File(Constants.PATH_TO_IMAGES+Constants.PATH_THUMBNAIL+fileName+".jpg");
ImageIO.write(image, "png", file); //saving scaled image
} catch (Exception e) {
e.printStackTrace();
}
}
return Response.status(Status.OK).entity("Filename:"+fileName).build();
}