com.squareup.okhttp.MultipartBuilder Java Examples

The following examples show how to use com.squareup.okhttp.MultipartBuilder. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: OkHttpStack.java    From AndNet with Apache License 2.0 6 votes vote down vote up
@Override
public void post(final String url, final RequestParams params,
                 final Net.Parser<T> parser,
                 final Net.Callback<T> callback,
                 final Object tag) {
    MultipartBuilder builder = createRequestBody(params);
    Request request = new Request.Builder()
            .url(url).post(builder.build()).build();
    call(request, parser, callback, tag);
}
 
Example #2
Source File: OkHttpUploadRequest.java    From meiShi with Apache License 2.0 6 votes vote down vote up
private void addParams(MultipartBuilder builder, Map<String, String> params)
{
    if (builder == null)
    {
        throw new IllegalArgumentException("builder can not be null .");
    }

    if (params != null && !params.isEmpty())
    {
        for (String key : params.keySet())
        {
            builder.addPart(Headers.of("Content-Disposition", "form-data; name=\"" + key + "\""),
                    RequestBody.create(null, params.get(key)));

        }
    }
}
 
Example #3
Source File: OkHttpUploadRequest.java    From meiShi with Apache License 2.0 6 votes vote down vote up
@Override
public RequestBody buildRequestBody()
{
    MultipartBuilder builder = new MultipartBuilder()
            .type(MultipartBuilder.FORM);
    addParams(builder, params);

    if (files != null)
    {
        RequestBody fileBody = null;
        for (int i = 0; i < files.length; i++)
        {
            Pair<String, File> filePair = files[i];
            String fileKeyName = filePair.first;
            File file = filePair.second;
            String fileName = file.getName();
            fileBody = RequestBody.create(MediaType.parse(guessMimeType(fileName)), file);
            builder.addPart(Headers.of("Content-Disposition",
                            "form-data; name=\"" + fileKeyName + "\"; filename=\"" + fileName + "\""),
                    fileBody);
        }
    }

    return builder.build();
}
 
Example #4
Source File: PostFormRequest.java    From NewsMe with Apache License 2.0 5 votes vote down vote up
private void addParams(MultipartBuilder builder)
{
    if (params != null && !params.isEmpty())
    {
        for (String key : params.keySet())
        {
            builder.addPart(Headers.of("Content-Disposition", "form-data; name=\"" + key + "\""),
                    RequestBody.create(null, params.get(key)));
        }
    }
}
 
Example #5
Source File: OkHttpStack.java    From AndNet with Apache License 2.0 4 votes vote down vote up
@Override
public void put(final String url, final RequestParams params,
                final Net.Parser<T> parser,
                final Net.Callback<T> callback,
                final Object tag) {
    MultipartBuilder builder = createRequestBody(params);
    Request request = new Request.Builder()
            .url(url).put(builder.build()).build();
    call(request, parser, callback, tag);
}