Hi I am uploading files on server using multipart entity but it only upload small files on php server now I want to upload large files using multipart entity so how can I do this?
-I am getting large file from sdcard
public String uploadfile(String uploadFile, String crimedetails, String lat)
{
String url;
MultipartEntity entity;
try {
url = String.format(WSConstants.SERVER_URL
+ WSConstants.URL_SET_POST);
entity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
//
File file = new File(uploadFile);
if (file.exists())
{
InputStream inputStream = null;
ByteArrayOutputStream bos = null;
try
{
inputStream = new FileInputStream(file);
bos = new ByteArrayOutputStream();
//byte[] b = new byte[1 * 1024 * 1024];
byte[] b = new byte[1024 * 8];
int bytesRead = 0;
while ((bytesRead = inputStream.read(b)) != -1)
{
System.gc();
bos.write(b, 0, bytesRead);
bos.flush();
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
InputStream in = new ByteArrayInputStream(bos.toByteArray());
ContentBody foto = new InputStreamBody(in, "application/pdf",uploadFile);
entity.addPart("uploadfile", foto);
}
else {
FormBodyPart image = new FormBodyPart("uploadfile",
new StringBody(""));
entity.addPart(image);
}
FormBodyPart userId = new FormBodyPart("filename", new StringBody(
String.valueOf(crimedetails)));
entity.addPart(userId);
FormBodyPart crimeType = new FormBodyPart("filetime",
new StringBody(String.valueOf(lat)));
entity.addPart(crimeType);
} catch (UnsupportedEncodingException e1) {
e1.printStackTrace();
return "error";
}
HttpParams httpParams = new BasicHttpParams();
HttpContext httpContext = new BasicHttpContext();
HttpConnectionParams.setConnectionTimeout(httpParams, 10000);
HttpConnectionParams.setSoTimeout(httpParams, 10000);
String result = null;
try {
HttpPost httpPost = new HttpPost(url);
httpPost.setEntity(entity);
HttpClient client = new DefaultHttpClient();
HttpResponse response = client.execute(httpPost);
BufferedReader in = null;
try {
in = new BufferedReader(new InputStreamReader(response
.getEntity().getContent()));
StringBuffer sb = new StringBuffer();
String line = null;
String NL = System.getProperty("line.separator");
while ((line = in.readLine()) != null) {
sb.append(line + NL);
}
result = sb.toString();
} finally {
if (in != null)
in.close();
}
} catch (Exception e) {
e.printStackTrace();
}
return result;
}