当前位置: 首页>>代码示例>>Java>>正文


Java MultipartBuilder.build方法代码示例

本文整理汇总了Java中com.squareup.okhttp.MultipartBuilder.build方法的典型用法代码示例。如果您正苦于以下问题:Java MultipartBuilder.build方法的具体用法?Java MultipartBuilder.build怎么用?Java MultipartBuilder.build使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.squareup.okhttp.MultipartBuilder的用法示例。


在下文中一共展示了MultipartBuilder.build方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: asyncMultipartPost

import com.squareup.okhttp.MultipartBuilder; //导入方法依赖的package包/类
private void asyncMultipartPost(String url, StringMap fields, ProgressHandler
        progressHandler, String fileName, RequestBody file, CompletionHandler
        completionHandler, CancellationHandler cancellationHandler) {
    if (this.converter != null) {
        url = this.converter.convert(url);
    }
    final MultipartBuilder mb = new MultipartBuilder();
    mb.addFormDataPart("file", fileName, file);
    fields.forEach(new Consumer() {
        public void accept(String key, Object value) {
            mb.addFormDataPart(key, value.toString());
        }
    });
    mb.type(MediaType.parse("multipart/form-data"));
    RequestBody body = mb.build();
    if (progressHandler != null) {
        body = new CountingRequestBody(body, progressHandler, cancellationHandler);
    }
    asyncSend(new Builder().url(url).post(body), null, completionHandler);
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:21,代码来源:Client.java

示例2: buildRequestBody

import com.squareup.okhttp.MultipartBuilder; //导入方法依赖的package包/类
@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();
}
 
开发者ID:dscn,项目名称:ktball,代码行数:26,代码来源:OkHttpUploadRequest.java

示例3: initRequestBody

import com.squareup.okhttp.MultipartBuilder; //导入方法依赖的package包/类
/**
 * 初始化Body类型请求参数
 * init Body type params
 */
private RequestBody initRequestBody(TreeMap<String , Object> params) {
    MultipartBuilder bodyBuilder = new MultipartBuilder().type(MultipartBuilder.FORM);
    Set<Map.Entry<String, Object>> entries = params.entrySet();
    for (Map.Entry<String, Object> entry : entries) {
        String key = entry.getKey();
        Object value = entry.getValue();

        if (value instanceof File) {
            File file = (File) value;
            try {
                FileNameMap fileNameMap = URLConnection.getFileNameMap();
                String mimeType = fileNameMap.getContentTypeFor(file.getAbsolutePath());
                XgoLog.w("mimeType::" + mimeType);
                bodyBuilder.addFormDataPart(key, file.getName(), RequestBody.create(MediaType.parse(mimeType), file));
            } catch (Exception e) {
                e.printStackTrace();
                XgoLog.e("mimeType is Error !");
            }
        } else {
            XgoLog.w(key + "::" + value);
            bodyBuilder.addFormDataPart(key, value.toString());
        }
    }
    return bodyBuilder.build();
}
 
开发者ID:cowthan,项目名称:AyoSunny,代码行数:30,代码来源:XgoHttpClient.java

示例4: multipartPost

import com.squareup.okhttp.MultipartBuilder; //导入方法依赖的package包/类
private Response multipartPost(String url,
                               StringMap fields,
                               String name,
                               String fileName,
                               RequestBody file,
                               StringMap headers) throws QiniuException {
    final MultipartBuilder mb = new MultipartBuilder();
    mb.addFormDataPart(name, fileName, file);

    fields.forEach(new StringMap.Consumer() {
        @Override
        public void accept(String key, Object value) {
            mb.addFormDataPart(key, value.toString());
        }
    });
    mb.type(MediaType.parse("multipart/form-data"));
    RequestBody body = mb.build();
    Request.Builder requestBuilder = new Request.Builder().url(url).post(body);
    return send(requestBuilder, headers);
}
 
开发者ID:charsdavy,项目名称:QiNiuGenertorToken,代码行数:21,代码来源:Client.java

示例5: buildMultipartFormRequest

import com.squareup.okhttp.MultipartBuilder; //导入方法依赖的package包/类
private Request buildMultipartFormRequest(String url, String[] fileKeys, File[] files, Param[] paramses) {
    paramses = validateParam(paramses);
    MultipartBuilder builder = new MultipartBuilder().type(MultipartBuilder.FORM);

    for (Param param : paramses) {
        builder.addPart(Headers.of("Content-Disposition", "form-data; name=\"" + param.key + "\""), RequestBody.create(null, param.value));
    }

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

    RequestBody requestBody = builder.build();
    return new Request.Builder().url(url).post(requestBody).build();
}
 
开发者ID:g977284333,项目名称:KwPresent,代码行数:22,代码来源:DownLoadManager.java

示例6: buildRequestBody

import com.squareup.okhttp.MultipartBuilder; //导入方法依赖的package包/类
@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();
}
 
开发者ID:bmbstack,项目名称:android-kit-old,代码行数:23,代码来源:OkHttpUploadRequest.java

示例7: buildMultipartFormRequest

import com.squareup.okhttp.MultipartBuilder; //导入方法依赖的package包/类
private RequestBody buildMultipartFormRequest(String[] fileKeys, File[] files, Map<String, String> params) {
    MultipartBuilder builder = new MultipartBuilder().type(MultipartBuilder.FORM);
    for (Map.Entry<String, String> entry : params.entrySet()) {
        builder.addPart(Headers.of("Content-Disposition", "form-data;name=\"" + entry.getKey() + "\""), RequestBody.create(null, entry.getValue()));
    }
    if (files != null && fileKeys != null && files.length == fileKeys.length) {
        RequestBody fileBody = null;
        for (int i = 0; i < files.length; i++) {
            fileBody = RequestBody.create(MediaType.parse(getMimeType(files[i].getName())), files[i]);
            builder.addPart(Headers.of("Content-Disposition",
                    "form-data;name=\"" + fileKeys[i] + "\";filename=\"" + files[i].getName() + "\""), fileBody);
        }
    } else {
        try {
            throw new Exception("文件名参数长度和文件实体内容长度不一致");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    return builder.build();
}
 
开发者ID:hjw541988478,项目名称:OkHttpTutorial,代码行数:22,代码来源:OkHttpUtil.java

示例8: buildMultipartFormRequest

import com.squareup.okhttp.MultipartBuilder; //导入方法依赖的package包/类
private Request buildMultipartFormRequest(String url, File[] files,
                                          String[] fileKeys, Param[] params) {
    params = validateParam(params);

    MultipartBuilder builder = new MultipartBuilder()
            .type(MultipartBuilder.FORM);

    for (Param param : params) {
        builder.addPart(Headers.of("Content-Disposition", "form-data; name=\"" + param.key + "\""),
                RequestBody.create(null, param.value));
    }
    if (files != null) {
        RequestBody fileBody = null;
        for (int i = 0; i < files.length; i++) {
            File file = files[i];
            String fileName = file.getName();
            fileBody = RequestBody.create(MediaType.parse(guessMimeType(fileName)), file);
            //TODO 根据文件名设置contentType
            builder.addPart(Headers.of("Content-Disposition",
                    "form-data; name=\"" + fileKeys[i] + "\"; filename=\"" + fileName + "\""),
                    fileBody);
        }
    }

    RequestBody requestBody = builder.build();
    return new Request.Builder()
            .url(url)
            .post(requestBody)
            .build();
}
 
开发者ID:NaOHAndroid,项目名称:Logistics-guard,代码行数:31,代码来源:OkHttpClientManager.java

示例9: getRequestBody

import com.squareup.okhttp.MultipartBuilder; //导入方法依赖的package包/类
private RequestBody getRequestBody(Map<String, T> formParams) {
    MultipartBuilder multiBuilder = new MultipartBuilder().type(MultipartBuilder.FORM);
    for (Map.Entry<String,T> entry : formParams.entrySet()) {
        String key = entry.getKey();
        T value = entry.getValue();
        if (value instanceof String) {
            multiBuilder.addFormDataPart(key, String.valueOf(value));
        }else if (value instanceof File){
            multiBuilder.addPart(
                    Headers.of("Content-Disposition", "form-data;name=\"emoji\"; filename=\"" + key + "\""),
                    RequestBody.create(MEDIA_TYPE_STREAM, (File) value));
        }
    }
    return multiBuilder.build();
}
 
开发者ID:zhangdatao,项目名称:Emojier-Andriod,代码行数:16,代码来源:HttpPostRequest.java

示例10: buildMultipartFormRequest

import com.squareup.okhttp.MultipartBuilder; //导入方法依赖的package包/类
private Request buildMultipartFormRequest(String url, File[] files,
                                          String[] fileKeys, Param[] params, Object tag) {
    params = validateParam(params);

    MultipartBuilder builder = new MultipartBuilder()
            .type(MultipartBuilder.FORM);

    for (Param param : params) {
        builder.addPart(Headers.of("Content-Disposition", "form-data; name=\"" + param.key + "\""),
                RequestBody.create(null, param.value));
    }
    if (files != null) {
        RequestBody fileBody = null;
        for (int i = 0; i < files.length; i++) {
            File file = files[i];
            String fileName = file.getName();
            fileBody = RequestBody.create(MediaType.parse(guessMimeType(fileName)), file);
            // TODO 根据文件名设置contentType
            builder.addPart(Headers.of("Content-Disposition",
                            "form-data; name=\"" + fileKeys[i] + "\"; filename=\"" + fileName + "\""),
                    fileBody);
        }
    }

    RequestBody requestBody = builder.build();
    return new Request.Builder()
            .url(url)
            .post(requestBody)
            .tag(tag)
            .build();
}
 
开发者ID:pengwei1024,项目名称:AndroidGeek,代码行数:32,代码来源:OkHttpClientManager.java

示例11: buildMultipartFormRequest

import com.squareup.okhttp.MultipartBuilder; //导入方法依赖的package包/类
private Request buildMultipartFormRequest(String url, File[] files,
		String[] fileKeys, Param[] params) {
	params = validateParam(params);

	MultipartBuilder builder = new MultipartBuilder()
			.type(MultipartBuilder.FORM);

	for (Param param : params) {
		builder.addPart(
				Headers.of("Content-Disposition", "form-data; name=\""
						+ param.key + "\""),
				RequestBody.create(null, param.value));
	}
	if (files != null) {
		RequestBody fileBody = null;
		for (int i = 0; i < files.length; i++) {
			File file = files[i];
			String fileName = file.getName();
			fileBody = RequestBody.create(
					MediaType.parse(guessMimeType(fileName)), file);
			// TODO 根据文件名设置contentType
			builder.addPart(
					Headers.of("Content-Disposition", "form-data; name=\""
							+ fileKeys[i] + "\"; filename=\"" + fileName
							+ "\""), fileBody);
		}
	}

	RequestBody requestBody = builder.build();
	return new Request.Builder().url(url).post(requestBody).build();
}
 
开发者ID:justingboy,项目名称:CouldBooks,代码行数:32,代码来源:OkHttpClientManager.java

示例12: build

import com.squareup.okhttp.MultipartBuilder; //导入方法依赖的package包/类
private void build(final Map<String, String> params, final Map<String, Pair<File, String>> files) {
    MultipartBuilder multipartBuilder = new MultipartBuilder().type(MultipartBuilder.FORM);

    for (Map.Entry<String, Pair<File, String>> filePart : files.entrySet()) {
        Pair<File, String> filePair = filePart.getValue();

        File file = filePair.first;
        String mediaType = filePair.second;

        multipartBuilder.addFormDataPart(
                filePart.getKey(),
                file.getName(),
                RequestBody.create(MediaType.parse(mediaType), file)
        );
    }

    if (params != null) {
        for (Map.Entry<String, String> stringPart : params.entrySet()) {
            multipartBuilder.addFormDataPart(
                    stringPart.getKey(),
                    stringPart.getValue()
            );
        }
    }

    mRequestBody = multipartBuilder.build();
}
 
开发者ID:Qanvast,项目名称:cannon,代码行数:28,代码来源:MultipartRequest.java

示例13: upload

import com.squareup.okhttp.MultipartBuilder; //导入方法依赖的package包/类
private void upload() {


        if(file==null){
            Toast.makeText(this,"请先下载文件",Toast.LENGTH_SHORT).show();
            return;
        }

        progressDialog.setMessage("upload");
        progressDialog.show();
        progressDialog.setProgress(0);



        MultipartBuilder mb = new MultipartBuilder();
        mb.type(MultipartBuilder.FORM);
        mb.addFormDataPart("user_id", "74");
        mb.addFormDataPart("user_head", file.getName(), RequestBody.create(null, file));
        RequestBody requestBody = mb.build();

        String url="接口地址";

        DOkHttp.getInstance().uploadPost2ServerProgress(this,url,requestBody,new DOkHttp.MyCallBack(){

            @Override
            public void onFailure(Request request, IOException e) {
                tv_show.setText(e.getMessage());
            }

            @Override
            public void onResponse(String json) {
                progressDialog.dismiss();
                tv_show.setText(json);
            }
        },new DOkHttp.UIchangeListener(){

            @Override
            public void progressUpdate(long bytesWrite, long contentLength, boolean done) {
                int progress= (int) (bytesWrite*100/contentLength);

                progressDialog.setProgress(progress);

                tv_show.append(progress+"\n");
            }
        });

    }
 
开发者ID:Daemon1993,项目名称:DOkHttp,代码行数:48,代码来源:MainActivity.java


注:本文中的com.squareup.okhttp.MultipartBuilder.build方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。