我正在使用spring编写一个Web服务.
此服务将base64编码的图像作为String参数.
我想将此String解码为图像并上传到服务器.
@RequestMapping(value="/uploadImage",method = RequestMethod.POST)
public @ResponseBody String uploadImage(@RequestParam("encodedImage") String encodedImage)
{
byte[] imageByte= Base64.decodeBase64(encodedImage);
return null;
}
Run Code Online (Sandbox Code Playgroud)
sri*_*ari 11
下面的代码用于解码使用base 64编码的字符串并用于将图像上传到服务器。
这对我来说很好用..
@RequestMapping(value="/uploadImage2",method = RequestMethod.POST)
public @ResponseBody String uploadImage2(@RequestParam("imageValue") String imageValue,HttpServletRequest request)
{
try
{
//This will decode the String which is encoded by using Base64 class
byte[] imageByte=Base64.decodeBase64(imageValue);
String directory=servletContext.getRealPath("/")+"images/sample.jpg";
new FileOutputStream(directory).write(imageByte);
return "success ";
}
catch(Exception e)
{
return "error = "+e;
}
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
28249 次 |
最近记录: |