當前位置: 首頁>>代碼示例>>Java>>正文


Java MultipartBuilder類代碼示例

本文整理匯總了Java中com.squareup.okhttp.MultipartBuilder的典型用法代碼示例。如果您正苦於以下問題:Java MultipartBuilder類的具體用法?Java MultipartBuilder怎麽用?Java MultipartBuilder使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


MultipartBuilder類屬於com.squareup.okhttp包,在下文中一共展示了MultipartBuilder類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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: buildUpload

import com.squareup.okhttp.MultipartBuilder; //導入依賴的package包/類
private static Request buildUpload(ACTION action, File[] files,
		String[] filenames, Object requestBean) {
	String json = GsonTool.toJson(requestBean);
	MultipartBuilder builder = new MultipartBuilder()
			.type(MultipartBuilder.FORM);
	if (files != null) {
		for (int i = 0; i < filenames.length; i++) {
			builder.addPart(Headers.of("Content-Disposition",
					"form-data;name=\"" + "file" + i + "\";filename=\""
							+ filenames[i] + "\""), RequestBody.create(
					MediaType.parse("application/octet-stream"), files[i]));
		}
	}
	builder.addPart(
			Headers.of("Content-Disposition", "form-data; name=\""
					+ RequestArr.requestArg + "\""),
			RequestBody.create(null, json));
	String url = RequestArr.mainUrl + RequestArr.mUrls.get(action);
	return new Request.Builder().url(url).post(builder.build()).build();
}
 
開發者ID:wangcantian,項目名稱:Mobile-Office,代碼行數:21,代碼來源:RequestFactory.java

示例3: addParams

import com.squareup.okhttp.MultipartBuilder; //導入依賴的package包/類
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)));

        }
    }
}
 
開發者ID:dscn,項目名稱:ktball,代碼行數:18,代碼來源:OkHttpUploadRequest.java

示例4: 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

示例5: callGTMC

import com.squareup.okhttp.MultipartBuilder; //導入依賴的package包/類
public static String callGTMC(String url, String filepath) {
    try {
        // ---
        File zipFile = new File(filepath);

        // Use the imgur image upload API as documented at https://api.imgur.com/endpoints/image
        RequestBody requestBody = new MultipartBuilder().type(MultipartBuilder.FORM).addFormDataPart("zipFile", zipFile.getName(), RequestBody.create(MEDIA_TYPE_ZIP, zipFile)).build();
        Request request = new Request.Builder().url(url).post(requestBody).build();
        Response response = client.newCall(request).execute();
        if (!response.isSuccessful())
            throw new IOException("Unexpected code " + response);

        return response.body().string();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        return null;
    }
}
 
開發者ID:STEMLab,項目名稱:JOSM-IndoorEditor,代碼行數:20,代碼來源:RequestExecutor.java

示例6: 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

示例7: 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

示例8: 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

示例9: uploadDrawingBitmap

import com.squareup.okhttp.MultipartBuilder; //導入依賴的package包/類
private String uploadDrawingBitmap(String uploadUrl, Bitmap drawing) throws IOException, JSONException {
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    drawing.compress(Bitmap.CompressFormat.PNG, 0, bos);

    RequestBody value = RequestBody.create(MediaType.parse("image/png"), bos.toByteArray());
    RequestBody requestBody = new MultipartBuilder()
            .type(MultipartBuilder.FORM)
            .addFormDataPart("moment", "moment.png", value)
            .build();

    Request request = new Request.Builder()
            .url(uploadUrl)
            .post(requestBody)
            .build();

    Response response = client.newCall(request).execute();
    if (response.isSuccessful()) {
        JSONObject resultJson = new JSONObject(response.body().string());
        return resultJson.getString("blob-key");
    } else {
        throw new IOException("Unexpected code " + response);
    }
}
 
開發者ID:AndrewJack,項目名稱:moment-for-android-wear,代碼行數:24,代碼來源:RxMomentApi.java

示例10: 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

示例11: 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

示例12: BaseUploadRequest

import com.squareup.okhttp.MultipartBuilder; //導入依賴的package包/類
public BaseUploadRequest(String filePath,
		UploadProgressListener uploadListener,
		HttpCallback<ListResponseModel<AssetModel>> callback) {

	this.uploadListener = uploadListener;
	this.file = new File(filePath);
	this.requestBody = new CountingFileRequestBody(file, MediaTypes.OCTET_STREAM, this);
	RequestBody requestBody = new MultipartBuilder()
		.type(MultipartBuilder.FORM)
		.addFormDataPart(getMultipartEntityKey(), file.getName(), this.requestBody)
		.build();
	setRequestMethod(RequestMethod.POST, requestBody);
	setCallback(callback);
	setParser(new ListResponseParser<AssetModel>(AssetModel.class));
	setRequestOptions(new RequestOptions.RequestOptionsBuilder().setRunInSingleThread(true).build());
}
 
開發者ID:chute,項目名稱:Chute-SDK-V2-Android,代碼行數:17,代碼來源:BaseUploadRequest.java

示例13: 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

示例14: b

import com.squareup.okhttp.MultipartBuilder; //導入依賴的package包/類
public void b(File file, cw cwVar, OnFailureCallBack onFailureCallBack) {
    file.exists();
    a(new Builder().url("https://eco-api-upload.meiqia.com/upload").post(new MultipartBuilder
            ().type(MultipartBuilder.FORM).addFormDataPart("file", "file.amr", RequestBody
            .create(MediaType.parse("audio/amr"), file)).build()).build(), new cs(this,
            cwVar), onFailureCallBack);
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:8,代碼來源:bu.java

示例15: doPostImgHttpRequest

import com.squareup.okhttp.MultipartBuilder; //導入依賴的package包/類
public static String doPostImgHttpRequest(String url, File file)
		throws IOException {
	RequestBody requestBody = new MultipartBuilder()
			.type(MultipartBuilder.FORM)
			.addFormDataPart("buffer", file.getName(),
					RequestBody.create(MEDIA_TYPE_PNG, file)).build();
	Request request = new Request.Builder().url(url).post(requestBody)
			.build();
	Response response = client.newCall(request).execute();
	if (!response.isSuccessful()) {
		System.out.println("服務端錯誤:" + response);
		throw new IOException("Unexpected code " + response);
	}
	return response.body().string();
}
 
開發者ID:mallog,項目名稱:mohoo-wechat-card,代碼行數:16,代碼來源:OkHttpUtil.java


注:本文中的com.squareup.okhttp.MultipartBuilder類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。