Arquivo da tag: Jersey

Salvando imagens Base64 via Web Service REST – Java/Jersey

...
import java.io.ByteArrayInputStrem;
import Javax.ws.rs.FormParam;
import org.apache.commons.io.IOUtils;
...
public class CarResource {
  ...
  @Post
  @Path("/postPhotoBase64")
  @Cunsumes(MediaType.APPLICATION_FORM_URLENCODED)
  public Response postPhotoBase64(@FormParam("fileName") String fileName, @FormParam("base64") String base64) {
    ...
    byte[] bytes = Base64.getDecoder().decode(base64);
    InputStream in = new ByteArrayInputStream(bytes);
    File tmpDir = new File(System.getProperty("java.io.tmpdir"), "cars");
    if (!tmpDir.exists()) {
      tmpDir.mkdir();
    }
    File file = new File(tmpDir, "Nome_Arquivo");
    FileOutputStream out = new FileOutputStream(file);
    IOUtils.copy(in, out);
    IOUtils.closeQuietly(out);
  }
}