zendesk에 첨부 파일을 업로드하려고합니다. 당신이 사용해야하는 API 문서에서자바가있는 zendesk에 첨부 파일 업로드
curl -u username:password -H "Content-Type: application/binary" \
--data-binary @file.dat -X POST \
"https://helpdesk.zendesk.com/api/v2/uploads.json?filename=myfile.dat&token= {optional_token}"
나는 자바로 똑같은 일을하려하고있다. 파일을 업로드하고 올바른 json 응답을받을 수 있습니다. 그러나 zendesk 서버에서 파일을 열면 파일이 인식되지 않습니다. 커맨드 라인에서 같은 파일을 컬 (curl)로 업로드하면 모든 것이 정상적으로 작동합니다. 여기서 내가 뭘 잘못하고 있니? 이 파일을 업로드하는 데 사용하는 Java 코드입니다. 나는 java client for zendesk
에 노력하고있다
public static void main(String[] args) throws IOException {
File file = new File("C:\\Users\\user\\Documents\\zendesk2\\Zendesk\\src\\main\\resources\\scrat.jpg");
try {
MultipartEntity multipartEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
multipartEntity.addPart("filename", new StringBody(file.getName()));
FileBody fileBody = new FileBody(file, "application/octet-stream");
multipartEntity.addPart("attachment", fileBody);
// -u admin:password
Credentials credentials = new UsernamePasswordCredentials("username", "passw");
DefaultHttpClient httpClient = new DefaultHttpClient();
httpClient.getCredentialsProvider().setCredentials(AuthScope.ANY, credentials);
// -X POST
HttpPost httpPost = new HttpPost("https://testserver.zendesk.com/api/v2/uploads.json");
// @ - absolute path
httpPost.setEntity(multipartEntity);
// process response
HttpResponse response = httpClient.execute(httpPost);
HttpEntity resEntity = response.getEntity();
if (resEntity != null) {
long len = resEntity.getContentLength();
if (len != -1 && len < 2048) {
// this result is being parsed with gson....
System.out.println(EntityUtils.toString(resEntity));
} else {
// Stream content out
}
}
httpClient.getConnectionManager().shutdown();
} catch (Exception e) {
//-f, fail silently}
}
}
이 잘하지만 전체 예가 아니다? 논리적 인 다음 단계는 어떻게 든 주어진 티켓에서 업로드를 사용 가능하게하는 것입니다. –