작업은
는 "데이터 파라미터 인코딩 된 다중 형태로 인코딩하거나,베이스 64와 엔드/이미지에서 HTTP POST 요청을 사용하여 이미지를 전송합니다."서버베이스 64를 부호화 영상 전송
내 이미지 인식 프로젝트에 Cloudsight API를 사용하고 있습니다. Refference http://docs.cloudsight.apiary.io/#reference/0/images-collection/send-an-image-for-identification
문제 내 코드에서 문제를 찾을 수 없습니다 내가 base64format로 인코딩 갤러리에서 이미지를 보낼 필요,하지만 난 서버 오류 (500)를 얻을 수
어쩌면 이미지가 인코딩되지 않은 정확히?
코드
private String uploadData(String url) {
String sResponse = "";
try {
HttpClient httpClient = new DefaultHttpClient();
HttpContext localContext = new BasicHttpContext();
HttpPost httpPost = new HttpPost(url+"/images");
httpPost.addHeader("Content-Type", "application/json");
httpPost.addHeader("Authorization", "CloudSight API_KEY");
ByteArrayOutputStream bos = new ByteArrayOutputStream();
bitmapImage.compress(Bitmap.CompressFormat.JPEG, 100, bos);
byte[] data = bos.toByteArray();
String encImage = Base64.encodeToString(data, Base64.DEFAULT);
JSONObject obj = new JSONObject();
obj.put("remote_image_url",encImage);
obj.put("locale", "en");
httpPost.setEntity(new StringEntity(obj.toString()));
HttpResponse response = httpClient.execute(httpPost, localContext);
int responseCode = response.getStatusLine().getStatusCode();
sResponse = inputStreamToString(
response.getEntity().getContent()).toString();
Log.i("ResponseString", sResponse);
Log.i("code", responseCode+"");
} catch (Exception ex) {
ex.printStackTrace();
}
return sResponse;
}
private class uploadImage1 extends AsyncTask<String, String, String>{
ProgressBar progressBar = new ProgressBar(getApplication(), null, android.R.attr.progressBarStyleSmall);
protected void onPreExecute() {
progressBar = (ProgressBar) findViewById(R.id.progressBar);
progressBar.setVisibility(View.VISIBLE);
super.onPreExecute();
}
@Override
protected String doInBackground(String... params) {
String url = params[0];
String sResponse = uploadData(url);
return sResponse;
}
}
편집
은 "참고 :. 우리가 1024 × 올라 오지 이미지 해상도, 5-8 사이의 JPEG 압축 수준을 권장 우리는 내부적으로 다른 이미지 크기를 조정 요청 프로세스가 느려질 수 있습니다. "
그래서 보내기 전에 크기를 조정해야합니까? 몇 가지 예를 들려 줄 수 있습니까?
서버 (500)는 내부 서버 에러입니다. 친절하게 서버 팀에게 해결을 요청하십시오. –
"참고 : 1024x 이하의 이미지 해상도와 5-8 사이의 JPEG 압축 수준을 권장합니다. 내부적으로 이미지의 크기를 조정하면 요청 프로세스가 느려질 수 있습니다." 그래서 보내기 전에 이미지의 크기를 조정해야합니까? 몇 가지 예를 들려 줄 수 있습니까? –
안녕하세요. 1) 코드 형식을 지정하는 데 더 많은 노력을 기울이십시오. 2) 스 니펫을 왜 사용하고 있습니까? 3) 과제입니까? 다음 번에는 형식을 올바르게 지정하여 소스 작업이 무엇인지, 어떤 질문을 제기하는지 이해하십시오. 4) 여러 개의 무작위 및 광범위한 질문 대신 특정 질문을하십시오. 아무도 완전한 해결책의 예를 공유하지 않을 것입니다. 사이트입니다. 5) 더 이상 게시하기 전에 이것을 읽어보십시오. https://stackoverflow.com/help/asking –