我正在尝试将图像的编码字节转换为base64格式并发送到rest webservice。在服务内部,我想对其进行解码并将其转换回图像并希望将图像保存在我的本地路径中。它在解码过程中失败。我不知道逻辑是否正确。需要一些指导
@POST
@Path("/imageupload")
@Produces("text/html")
@Consumes(MediaType.MULTIPART_FORM_DATA)
public String execute(@FormDataParam("image") String inputfile) throws Exception
{
System.out.println("entered into service");
BASE64Decoder decoder = new BASE64Decoder();
ByteBuffer img=decoder.decodeBufferToByteBuffer(inputfile);
System.out.println();
File outputfile = new File("D:\\TEST\\test.png");
ImageIO.write(img, "png", outputfile);
逻辑是:
Step 1: get the byte array as string inside the service.
Step 2: decode it
Step 3: write the byte into file with png format