Search in sources :

Example 1 with Part

use of com.android.internal.http.multipart.Part in project android_frameworks_base by ParanoidAndroid.

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;
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) MultipartEntity(com.android.internal.http.multipart.MultipartEntity) Part(com.android.internal.http.multipart.Part) FilePart(com.android.internal.http.multipart.FilePart) StringPart(com.android.internal.http.multipart.StringPart) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) HttpClient(org.apache.http.client.HttpClient) StringPart(com.android.internal.http.multipart.StringPart) HttpResponse(org.apache.http.HttpResponse) IOException(java.io.IOException) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) FilePart(com.android.internal.http.multipart.FilePart)

Example 2 with Part

use of com.android.internal.http.multipart.Part in project platform_frameworks_base by android.

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;
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) MultipartEntity(com.android.internal.http.multipart.MultipartEntity) Part(com.android.internal.http.multipart.Part) FilePart(com.android.internal.http.multipart.FilePart) StringPart(com.android.internal.http.multipart.StringPart) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) HttpClient(org.apache.http.client.HttpClient) StringPart(com.android.internal.http.multipart.StringPart) HttpResponse(org.apache.http.HttpResponse) IOException(java.io.IOException) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) FilePart(com.android.internal.http.multipart.FilePart)

Example 3 with Part

use of com.android.internal.http.multipart.Part in project android_frameworks_base by crdroidandroid.

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;
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) MultipartEntity(com.android.internal.http.multipart.MultipartEntity) Part(com.android.internal.http.multipart.Part) FilePart(com.android.internal.http.multipart.FilePart) StringPart(com.android.internal.http.multipart.StringPart) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) HttpClient(org.apache.http.client.HttpClient) StringPart(com.android.internal.http.multipart.StringPart) HttpResponse(org.apache.http.HttpResponse) IOException(java.io.IOException) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) FilePart(com.android.internal.http.multipart.FilePart)

Example 4 with Part

use of com.android.internal.http.multipart.Part in project android_frameworks_base by AOSPA.

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;
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) MultipartEntity(com.android.internal.http.multipart.MultipartEntity) Part(com.android.internal.http.multipart.Part) FilePart(com.android.internal.http.multipart.FilePart) StringPart(com.android.internal.http.multipart.StringPart) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) HttpClient(org.apache.http.client.HttpClient) StringPart(com.android.internal.http.multipart.StringPart) HttpResponse(org.apache.http.HttpResponse) IOException(java.io.IOException) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) FilePart(com.android.internal.http.multipart.FilePart)

Example 5 with Part

use of com.android.internal.http.multipart.Part in project android_frameworks_base by DirtyUnicorns.

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;
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) MultipartEntity(com.android.internal.http.multipart.MultipartEntity) Part(com.android.internal.http.multipart.Part) FilePart(com.android.internal.http.multipart.FilePart) StringPart(com.android.internal.http.multipart.StringPart) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) HttpClient(org.apache.http.client.HttpClient) StringPart(com.android.internal.http.multipart.StringPart) HttpResponse(org.apache.http.HttpResponse) IOException(java.io.IOException) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) FilePart(com.android.internal.http.multipart.FilePart)

Aggregations

FilePart (com.android.internal.http.multipart.FilePart)6 MultipartEntity (com.android.internal.http.multipart.MultipartEntity)6 Part (com.android.internal.http.multipart.Part)6 StringPart (com.android.internal.http.multipart.StringPart)6 IOException (java.io.IOException)6 HttpResponse (org.apache.http.HttpResponse)6 HttpClient (org.apache.http.client.HttpClient)6 HttpPost (org.apache.http.client.methods.HttpPost)6 DefaultHttpClient (org.apache.http.impl.client.DefaultHttpClient)6