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


Java HttpMultipartMode类代码示例

本文整理汇总了Java中org.apache.http.entity.mime.HttpMultipartMode的典型用法代码示例。如果您正苦于以下问题:Java HttpMultipartMode类的具体用法?Java HttpMultipartMode怎么用?Java HttpMultipartMode使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


HttpMultipartMode类属于org.apache.http.entity.mime包,在下文中一共展示了HttpMultipartMode类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: setupMultipartEntity

import org.apache.http.entity.mime.HttpMultipartMode; //导入依赖的package包/类
private void setupMultipartEntity(HttpPost httpPost){
    if(isDebug){
        log("Request upload file:"+mFile.getName() +"  exists:"+ mFile.exists());
    }
    MultipartEntityBuilder entity = MultipartEntityBuilder.create()
            .seContentType(ContentType.MULTIPART_FORM_DATA)
            .setMode(HttpMultipartMode.BROWSER_COMPATIBLE)
            .addBinaryBody(mName,mFile,ContentType.DEFAULT_BINARY,mFileName) //uploadFile对应服务端类的同名属性<File类型>
            .setCharset(DEFAULT_CHARSET);

    for (String key:mFileParames.keySet()) {
        String value = mFileParames.get(key);
        entity.addTextBody(key,value);
    }
    httpPost.setEntity(entity.build());
}
 
开发者ID:fcibook,项目名称:QuickHttp,代码行数:17,代码来源:QuickHttpController.java

示例2: addTpl

import org.apache.http.entity.mime.HttpMultipartMode; //导入依赖的package包/类
/**
 * 
 * @param param
 *            apikey sign
 * @param layout
 *            {@code VideoLayout}
 * @param material
 *            视频资料zip文件
 * 
 * @return
 */
public Result<Template> addTpl(Map<String, String> param, String layout, byte[] material) {
    Result<Template> r = new Result<>();
    if (layout == null || material == null) return r.setCode(Code.ARGUMENT_MISSING);
    List<NameValuePair> list = param2pair(param, r, APIKEY, SIGN);
    if (r.getCode() != Code.OK) return r;

    Charset ch = Charset.forName(charset());
    MultipartEntityBuilder builder = MultipartEntityBuilder.create().setCharset(ch).setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
    for (NameValuePair pair : list) {
        builder.addTextBody(pair.getName(), pair.getValue(), ContentType.create("text/plain", ch));
    }
    builder.addTextBody(LAYOUT, layout, ContentType.APPLICATION_JSON);
    builder.addBinaryBody(MATERIAL, material, ContentType.create("application/octet-stream", ch), null);

    StdResultHandler<Template> h = new StdResultHandler<>();
    try {
        return path("add_tpl.json").post(new HttpEntityWrapper(builder.build()), h, r);
    } catch (Exception e) {
        return h.catchExceptoin(e, r);
    }
}
 
开发者ID:yunpian,项目名称:yunpian-java-sdk,代码行数:33,代码来源:VideoSmsApi.java

示例3: execute

import org.apache.http.entity.mime.HttpMultipartMode; //导入依赖的package包/类
@Override
public WxMediaUploadResult execute(String uri, File file) throws WxErrorException, IOException {
  HttpPost httpPost = new HttpPost(uri);
  if (requestHttp.getRequestHttpProxy() != null) {
    RequestConfig config = RequestConfig.custom().setProxy(requestHttp.getRequestHttpProxy()).build();
    httpPost.setConfig(config);
  }
  if (file != null) {
    HttpEntity entity = MultipartEntityBuilder
      .create()
      .addBinaryBody("media", file)
      .setMode(HttpMultipartMode.RFC6532)
      .build();
    httpPost.setEntity(entity);
  }
  try (CloseableHttpResponse response = requestHttp.getRequestHttpClient().execute(httpPost)) {
    String responseContent = Utf8ResponseHandler.INSTANCE.handleResponse(response);
    WxError error = WxError.fromJson(responseContent);
    if (error.getErrorCode() != 0) {
      throw new WxErrorException(error);
    }
    return WxMediaUploadResult.fromJson(responseContent);
  } finally {
    httpPost.releaseConnection();
  }
}
 
开发者ID:binarywang,项目名称:weixin-java-tools,代码行数:27,代码来源:ApacheMediaUploadRequestExecutor.java

示例4: addStreamToEntity

import org.apache.http.entity.mime.HttpMultipartMode; //导入依赖的package包/类
/**
 * Adds a stream to an HTTP entity
 *
 * @param someStream Input stream to be added to an HTTP entity
 * @param fieldName A description of the entity content
 * @param fileName Name of the file attached as an entity
 * @return HTTP entity
 * @throws IOException Signals a failure while reading the input stream
 */
HttpEntity addStreamToEntity(InputStream someStream, String fieldName, String fileName) throws IOException {
    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
    int bytesRead;
    byte[] bytes = new byte[1024];
    while ((bytesRead = someStream.read(bytes)) > 0) {
        byteArrayOutputStream.write(bytes, 0, bytesRead);
    }
    byte[] data = byteArrayOutputStream.toByteArray();

    MultipartEntityBuilder builder = MultipartEntityBuilder.create();
    builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
    builder.setStrictMode();
    builder.addBinaryBody(fieldName, data, ContentType.MULTIPART_FORM_DATA, fileName);
    return builder.build();
}
 
开发者ID:Microsoft,项目名称:Cognitive-SpeakerRecognition-Android,代码行数:25,代码来源:SpeakerRestClientHelper.java

示例5: postForm

import org.apache.http.entity.mime.HttpMultipartMode; //导入依赖的package包/类
private HttpPost postForm(String url, Map<String, String> params, Map<String, File> files, String charset) {
    if (StringUtils.isBlank(charset)) {
        charset = "UTF-8";
    }

    HttpPost httpPost = new HttpPost(url);
    MultipartEntityBuilder builder = MultipartEntityBuilder.create();
    if (null != params) {
        Set<String> keySet = params.keySet();
        for (String key : keySet) {
            builder.addTextBody(key, params.get(key), ContentType.create("text/plain", Charset.forName(charset)));
        }
    }
    if (CollectionUtils.isBlank(files)) {
        for (String filename : files.keySet()) {
            builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
            builder.addBinaryBody(filename, files.get(filename), ContentType.DEFAULT_BINARY, filename);
        }
    }
    httpPost.setEntity(builder.build());

    return httpPost;
}
 
开发者ID:storezhang,项目名称:utils,代码行数:24,代码来源:HttpClient.java

示例6: composeMultiPartFormRequest

import org.apache.http.entity.mime.HttpMultipartMode; //导入依赖的package包/类
private HttpPost composeMultiPartFormRequest(final String uri, final Parameters parameters, final Map<String, ContentBody> files) {
	HttpPost request = new HttpPost(uri);
	MultipartEntity multiPartEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);

	try {
		Charset utf8 = Charset.forName("UTF-8");
		for(Parameter param : parameters)
			if(param.isSingleValue())
				multiPartEntity.addPart(param.getName(), new StringBody(param.getValue(), utf8));
			else
				for(String value : param.getValues())
					multiPartEntity.addPart(param.getName(), new StringBody(value, utf8));
	} catch (UnsupportedEncodingException e) {
		throw MechanizeExceptionFactory.newException(e);
	}

	List<String> fileNames = new ArrayList<String>(files.keySet());
	Collections.sort(fileNames);
	for(String name : fileNames) {
		ContentBody contentBody = files.get(name);
		multiPartEntity.addPart(name, contentBody);
	}
	request.setEntity(multiPartEntity);
	return request;
}
 
开发者ID:Coffeeboys,项目名称:RenewPass,代码行数:26,代码来源:RequestBuilder.java

示例7: initRequest

import org.apache.http.entity.mime.HttpMultipartMode; //导入依赖的package包/类
public HttpPost initRequest(final FileUploadParameter parameter) {
	final FileUploadAddress fileUploadAddress = getDependResult(FileUploadAddress.class);
	final HttpPost request = new HttpPost("http://" + fileUploadAddress.getData().getUp() + CONST.URI_PATH);
	final MultipartEntityBuilder multipartEntity = MultipartEntityBuilder.create();
	multipartEntity.setCharset(Consts.UTF_8);
	multipartEntity.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
	multipartEntity.addPart(CONST.QID_NAME, new StringBody(getLoginInfo().getQid(), ContentType.DEFAULT_BINARY));
	multipartEntity.addPart("ofmt", new StringBody("json", ContentType.DEFAULT_BINARY));
	multipartEntity.addPart("method", new StringBody("Upload.web", ContentType.DEFAULT_BINARY));
	multipartEntity.addPart("token", new StringBody(readCookieStoreValue("token"), ContentType.DEFAULT_BINARY));
	multipartEntity.addPart("v", new StringBody("1.0.1", ContentType.DEFAULT_BINARY));
	multipartEntity.addPart("tk", new StringBody(fileUploadAddress.getData().getTk(), ContentType.DEFAULT_BINARY));
	multipartEntity.addPart("Upload", new StringBody("Submit Query", ContentType.DEFAULT_BINARY));
	multipartEntity.addPart("devtype", new StringBody("web", ContentType.DEFAULT_BINARY));
	multipartEntity.addPart("pid", new StringBody("ajax", ContentType.DEFAULT_BINARY));
	multipartEntity.addPart("Filename",
			new StringBody(parameter.getUploadFile().getName(), ContentType.APPLICATION_JSON));
	multipartEntity.addPart("path", new StringBody(parameter.getPath(), ContentType.APPLICATION_JSON));// 解决中文不识别问题
	multipartEntity.addBinaryBody("file", parameter.getUploadFile());
	request.setEntity(multipartEntity.build());
	return request;
}
 
开发者ID:dounine,项目名称:clouddisk,代码行数:23,代码来源:FileUploadParser.java

示例8: main

import org.apache.http.entity.mime.HttpMultipartMode; //导入依赖的package包/类
public static void main(String args[]){
    HttpClient httpClient = HttpClients.createDefault();
    HttpPost httpPost = new HttpPost("http://localhost:8080/sso-web/upload");
    httpPost.addHeader("Range","bytes=10000-");
    final MultipartEntityBuilder multipartEntity = MultipartEntityBuilder.create();
    multipartEntity.setCharset(Consts.UTF_8);
    multipartEntity.setMode(HttpMultipartMode.STRICT);
    multipartEntity.addBinaryBody("file", new File("/Users/huanghuanlai/Desktop/test.java"));
    httpPost.setEntity(multipartEntity.build());
    try {
        HttpResponse response = httpClient.execute(httpPost);

    } catch (IOException e) {
        e.printStackTrace();
    }
}
 
开发者ID:dounine,项目名称:clouddisk,代码行数:17,代码来源:ClassTest.java

示例9: submitFile

import org.apache.http.entity.mime.HttpMultipartMode; //导入依赖的package包/类
public void submitFile(String recordID, String fileField, BlobSubmissionType blob_value,
                       CallingContext cc) throws MalformedURLException, IOException,
    ODKDatastoreException {

  String contentType = blob_value.getContentType(1, cc);
  String filename = blob_value.getUnrootedFilename(1, cc);
  filename = fileField + filename.substring(filename.lastIndexOf('.'));

  /**
   * REDCap server appears to be highly irregular in the structure of the
   * form-data submission it will accept from the client. The following should
   * work, but either resets the socket or returns a 403 error.
   */
  ContentType utf8Text = ContentType.create(ContentType.TEXT_PLAIN.getMimeType(), UTF_CHARSET);
  MultipartEntityBuilder builder = MultipartEntityBuilder.create();
  builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE)
      .setCharset(UTF_CHARSET);
  builder.addTextBody("token", getApiKey(), utf8Text)
      .addTextBody("content", "file", utf8Text)
      .addTextBody("action", "import", utf8Text)
      .addTextBody("record", recordID, utf8Text)
      .addTextBody("field", fileField, utf8Text)
      .addBinaryBody("file", blob_value.getBlob(1, cc), ContentType.create(contentType), filename);

  submitPost("File import", builder.build(), null, cc);
}
 
开发者ID:opendatakit,项目名称:aggregate,代码行数:27,代码来源:REDCapServer.java

示例10: fileUpload

import org.apache.http.entity.mime.HttpMultipartMode; //导入依赖的package包/类
private void fileUpload() throws Exception {
    httpPost = new NUHttpPost(postURL);
    MultipartEntity mpEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
    mpEntity.addPart("Filename", new StringBody(file.getName()));
    mpEntity.addPart("notprivate", new StringBody("false"));
    mpEntity.addPart("folder", new StringBody("/"));
    mpEntity.addPart("Filedata", createMonitoredFileBody()); 
    httpPost.setHeader("Cookie", usercookie);
    httpPost.setEntity(mpEntity);
    uploading();
    NULogger.getLogger().info("Now uploading your file into zippyshare.com");
    httpResponse = httpclient.execute(httpPost);
    gettingLink();
    HttpEntity resEntity = httpResponse.getEntity();
    if (resEntity != null) {
        uploadresponse = EntityUtils.toString(resEntity);
        downloadlink = StringUtils.stringBetweenTwoStrings(uploadresponse, "value=\"http://", "\"");
        downloadlink = "http://" + downloadlink;
        NULogger.getLogger().log(Level.INFO, "Download Link : {0}", downloadlink);
        downURL=downloadlink;
        
    }else{
        throw new Exception("ZippyShare server problem or Internet connectivity problem");
    }

}
 
开发者ID:Neembuu-Uploader,项目名称:neembuu-uploader,代码行数:27,代码来源:ZippyShare.java

示例11: MultipartRequest

import org.apache.http.entity.mime.HttpMultipartMode; //导入依赖的package包/类
public MultipartRequest(String url, Response.ErrorListener errorListener,
                        Response.Listener<String> listener, File file,
                        Map<String, String> mStringPart) {
    super(Method.POST, url, errorListener);

    this.mListener = listener;
    this.mFilePart = file;
    this.mStringPart = mStringPart;

    entity.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
    try {
        entity.setCharset(CharsetUtils.get("UTF-8"));
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }
    buildMultipartEntity();
    httpentity = entity.build();
}
 
开发者ID:spark3dp,项目名称:spark-android-SDK,代码行数:19,代码来源:MultipartRequest.java

示例12: fileUpload

import org.apache.http.entity.mime.HttpMultipartMode; //导入依赖的package包/类
private static void fileUpload() throws Exception {

        file = new File("C:\\Documents and Settings\\All Users\\Documents\\My Pictures\\Sample Pictures\\Sunset.jpg");
        httpclient = new DefaultHttpClient();
//http://upload3.divshare.com/cgi-bin/upload.cgi?sid=8ef15852c69579ebb2db1175ce065ba6

        HttpPost httppost = new HttpPost(downURL + "cgi-bin/upload.cgi?sid=" + sid);


        MultipartEntity mpEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
        ContentBody cbFile = new FileBody(file);
        mpEntity.addPart("file[0]", cbFile);

        httppost.setEntity(mpEntity);
        System.out.println("executing request " + httppost.getRequestLine());
        System.out.println("Now uploading your file into divshare.com");
        HttpResponse response = httpclient.execute(httppost);
        HttpEntity resEntity = response.getEntity();
        System.out.println(response.getStatusLine());
        System.out.println(EntityUtils.toString(resEntity));

    }
 
开发者ID:Neembuu-Uploader,项目名称:neembuu-uploader,代码行数:23,代码来源:DivShareUploaderPlugin.java

示例13: convertFromFileToFile

import org.apache.http.entity.mime.HttpMultipartMode; //导入依赖的package包/类
/**
 * Handles conversion from file to file with given File object
 * @param dest The output file object
 * @return True on success, false on error
 * @throws IOException 
 */
private boolean convertFromFileToFile(File dest) throws IOException {
    if (!this.getInputFile().exists()) {
        throw new IllegalArgumentException("MsWordToImageConvert: Input file was not found at '" + this.input.getValue() + "'");
    }

    HttpClient client = HttpClientBuilder.create().build();
    HttpPost post = new HttpPost(this.constructMsWordToImageAddress(new HashMap<>()));
    MultipartEntityBuilder builder = MultipartEntityBuilder.create();
    builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
    builder.addPart("file_contents", new FileBody(this.getInputFile()));
    post.setEntity(builder.build());
    
    HttpResponse response = client.execute(post);

    HttpEntity entity = response.getEntity();
    try (FileOutputStream fileOS = new FileOutputStream(dest)) {
        entity.writeTo(fileOS);
        fileOS.flush();
    }
    return true;
}
 
开发者ID:msword2image,项目名称:msword2image-java,代码行数:28,代码来源:MsWordToImageConvert.java

示例14: fileUpload

import org.apache.http.entity.mime.HttpMultipartMode; //导入依赖的package包/类
private static void fileUpload() throws IOException {
    HttpClient httpclient = new DefaultHttpClient();
    HttpPost httppost = new HttpPost(postURL);

    file = new File("h:/install.txt");
    MultipartEntity mpEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
    ContentBody cbFile = new FileBody(file);
    mpEntity.addPart("Filename", new StringBody(file.getName()));
    mpEntity.addPart("Filedata", cbFile);
    httppost.setEntity(mpEntity);
    System.out.println("executing request " + httppost.getRequestLine());
    System.out.println("Now uploading your file into sharesend.com");
    HttpResponse response = httpclient.execute(httppost);
    HttpEntity resEntity = response.getEntity();
    System.out.println(response.getStatusLine());
    if (resEntity != null) {
        uploadresponse = EntityUtils.toString(resEntity);
    }
    System.out.println("Upload Response : " + uploadresponse);
    System.out.println("Download Link : http://sharesend.com/" + uploadresponse);
    httpclient.getConnectionManager().shutdown();
}
 
开发者ID:Neembuu-Uploader,项目名称:neembuu-uploader,代码行数:23,代码来源:ShareSendUploaderPlugin.java

示例15: fileUpload

import org.apache.http.entity.mime.HttpMultipartMode; //导入依赖的package包/类
public static void fileUpload() throws Exception {
        DefaultHttpClient httpclient = new DefaultHttpClient();
        HttpPost httppost = new HttpPost(postURL);
        MultipartEntity reqEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
        //reqEntity.addPart("string_field",new StringBody("field value"));
        FileBody bin = new FileBody(new File("/home/vigneshwaran/VIGNESH/naruto.txt"));
        reqEntity.addPart("fff", bin);
        httppost.setEntity(reqEntity);
        System.out.println("Now uploading your file into 2shared.com. Please wait......................");
        HttpResponse response = httpclient.execute(httppost);
//        HttpEntity resEntity = response.getEntity();
//
//        if (resEntity != null) {
//            String page = EntityUtils.toString(resEntity);
//            System.out.println("PAGE :" + page);
//        }
    }
 
开发者ID:Neembuu-Uploader,项目名称:neembuu-uploader,代码行数:18,代码来源:TwoSharedUploaderPlugin.java


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