最近の検索


最近の検索はありません

Zendesk file upload through Spring boot REST



投稿日時:2022年5月12日

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,

Reference : https://support.zendesk.com/hc/en-us/community/posts/4588002835994-Uploaded-image-is-empty-or-corrupted?page=1#community_comment_4588190155802industrial-desk

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.


0

0

0件のコメント

サインインしてコメントを残してください。

お探しのものが見つかりませんか?

新規投稿