I'm trying to upload an image to the zendesk through its API, Once the file is uploaded I can get the token but files seems empty,
This is how my code looks like,
fis = new FileInputStream(file);
fis.read(contents);
byte[] encoded = Base64.encodeBase64(contents);
fis.close();
body.add("file", encoded);
HttpEntity<MultiValueMap<String, Object>> requestEntity = new HttpEntity<>(body, headers);
UploadResponseObject result = restTemplate.postForObject(
remoteUri + "/api/v2/uploads.json?filename=" + multipartFile.getOriginalFilename(),
new HttpEntity<>(body, headers),
UploadResponseObject.class);
I have tried with several different headers,
headers.set("Content-Disposition","form-data; name=\"attachment\"; filename=\"laptop_183544.jpg\"");
headers.add("Content-Type","image/jpeg");
headers.add("Content-Type","multipart/form-data");
headers.add("Content-Type","application/binary");
But nothing seems to be working, File is uploaded but always an 1 KB empty file.
Can someone please help me on this?
Thanks.
I just tried this and have an answer to this question, I just got it too complicated early. so here is the simple solution.