Maybe you can try this:
private class sendMissingImagesToServer extends
AsyncTask<String, Integer, byte[]> {
@Override
protected byte[] doInBackground(String... params) {
String uri = params[0];
byte[] data;
try {
MultipartEntityBuilder entity;
File f;
FileBody fb;
entity = MultipartEntityBuilder.create();
entity.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
f = new File(zipImageFile);
fb = new FileBody(f);
entity.addPart("orderFile", fb);
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(uri);
Log.e("Uploload Missing Image URL", "" + uri);
httppost.setEntity(entity.build());
HttpResponse response = httpclient.execute(httppost);
InputStream input = response.getEntity().getContent();
data = new byte[input.available()];
input.read(data);
return data;
} catch (Exception e) {
return e.toString().getBytes();
}
}
@Override
protected void onPostExecute(byte[] result) {
// TODO Auto-generated method stub
super.onPostExecute(result);
Log.e("Response From Server", "" + result);
writeToFile(result);
}
}
@SuppressWarnings("resource")
private void writeToFile(byte[] data) {
try {
FileOutputStream fop = null;
File file;
file = new File(AppConstants.DataPath+"/products.zip");
fop = new FileOutputStream(file);
// if file doesnt exists, then create it
if (!file.exists()) {
file.createNewFile();
}
try {
fop.write(data);
} catch (IOException e) {
Log.e("Exception", "File write failed: " + e.toString());
}
unzipImage(AppConstants.DataPath + "/products.zip",
AppConstants.DataPath);
}catch (Exception E)
{
}
}
If you covert the bytes to a String
and then get bytes by String.getBytes()
,you need to assume that the encoding must be single-byte like iso-8859-1(not utf-8 nor others).
Change your code from
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
to
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(response.getEntity().getContent(),"ISO-8859-1"));
And then bObj.write(stringBuffer.toString().getBytes());
to
bObj.write(stringBuffer.toString().getBytes("ISO-8859-1"));