Трябва да изпратя снимка от файл, съхранен в SDCARD, към външен API. За да направя това, използвам следния код:
String responseStr = null;
this.setMethod(request);
this.setParameters(tags, parameters, optional);
String requested = mUri.build().toString();
HttpHost host = new HttpHost(API_REST_HOST, -1,
HttpHost.DEFAULT_SCHEME_NAME);
Log.d(TAG, requested);
try {
HttpPost post = new HttpPost(requested);
File file = new File(filepath);
FileEntity fileentity;
if (filepath.substring(filepath.length()-3, filepath.length
()).equalsIgnoreCase("jpg")) {
fileentity = new FileEntity(file,"image/jpeg;");
fileentity.setChunked(true);
post.setEntity(fileentity);
}
post.addHeader("Content-Type", "image/jpeg;");
HttpResponse response = mClient.execute(host,post);
„setMethod“ и „setParameters“ са собствени методи за изграждане на Uri обекта. Външният api приема добре параметрите, но не и снимката. Очаква снимката в поле HttpBody.
Някаква идея? Благодаря
Благодаря