use of com.android.internal.http.multipart.StringPart in project android_frameworks_base by ResurrectionRemix.
the class BandwidthTestUtil method postFileToServer.
/**
* Post a given file for a given device and timestamp to the server.
* @param server {@link String} url of test server
* @param deviceId {@link String} device id that is uploading
* @param timestamp {@link String} timestamp
* @param file {@link File} to upload
* @return true if it succeeded
*/
public static boolean postFileToServer(String server, String deviceId, String timestamp, File file) {
try {
Log.d(LOG_TAG, "Uploading begining");
HttpClient httpClient = new DefaultHttpClient();
String uri = server;
if (!uri.endsWith("/")) {
uri += "/";
}
uri += "upload";
Log.d(LOG_TAG, "Upload url:" + uri);
HttpPost postRequest = new HttpPost(uri);
Part[] parts = { new StringPart("device_id", deviceId), new StringPart("timestamp", timestamp), new FilePart("file", file) };
MultipartEntity reqEntity = new MultipartEntity(parts, postRequest.getParams());
postRequest.setEntity(reqEntity);
HttpResponse res = httpClient.execute(postRequest);
res.getEntity().getContent().close();
} catch (IOException e) {
Log.e(LOG_TAG, "Could not upload file with error: " + e);
return false;
}
return true;
}
Aggregations