I want to upload multiple image at once. so I found 'MultipartEntityBuilder' but It is not working well.
It's my source...
public void executeMultipartPost() throws Exception {
try {
MultipartEntityBuilder builder = MultipartEntityBuilder.create();
builder.setCharset(Charset.forName("UTF-8"));
builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.PNG, 100, byteArrayOutputStream);
byteArray = byteArrayOutputStream.toByteArray();
builder.addTextBody("file1", byteArray.toString());
builder.addTextBody("file2", byteArray2.toString());
// send
InputStream inputStream = null;
HttpClient httpClient = AndroidHttpClient.newInstance("Android");
HttpPost httpPost = new HttpPost(UPLOAD_URL);
httpPost.setEntity(builder.build());
HttpResponse httpResponse = httpClient.execute(httpPost);
HttpEntity httpEntity = httpResponse.getEntity();
inputStream = httpEntity.getContent();
// response
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"));
StringBuilder stringBuilder = new StringBuilder();
String line = null;
while ((line = bufferedReader.readLine()) != null) {
stringBuilder.append(line + "\n");
}
inputStream.close();
// result
String result = stringBuilder.toString();
} catch (Exception e) {
e.printStackTrace();
}
}
When Debugging, 'httpPost.setEntity(builder.build())' this line is error.
and there is no 'Caused by~' ,but Process: NoSuchFiledError in logcat...
but I think I made image to bitmap then send it to FTP. what is wrong..? Thanks.