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


Java MediaType.MULTIPART_FORM_DATA屬性代碼示例

本文整理匯總了Java中org.springframework.http.MediaType.MULTIPART_FORM_DATA屬性的典型用法代碼示例。如果您正苦於以下問題:Java MediaType.MULTIPART_FORM_DATA屬性的具體用法?Java MediaType.MULTIPART_FORM_DATA怎麽用?Java MediaType.MULTIPART_FORM_DATA使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在org.springframework.http.MediaType的用法示例。


在下文中一共展示了MediaType.MULTIPART_FORM_DATA屬性的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: writeMultipart

private void writeMultipart(MultiValueMap<String, Object> parts, HttpOutputMessage outputMessage)
		throws IOException {
	byte[] boundary = generateMultipartBoundary();

	Map<String, String> parameters = Collections.singletonMap("boundary", new String(boundary, "US-ASCII"));
	MediaType contentType = new MediaType(MediaType.MULTIPART_FORM_DATA, parameters);
	outputMessage.getHeaders().setContentType(contentType);

	writeParts(outputMessage.getBody(), parts, boundary);
	writeEnd(boundary, outputMessage.getBody());
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:11,代碼來源:FormHttpMessageConverter.java

示例2: determineContentType

/**
 * Tries to determine the content/media type of this HTTP request iff the HTTP "Content-Type"
 * header was not explicitly set by the user, otherwise the user provided value is used. If the
 * "Content-Type" HTTP header value is null, then the content/media/payload of this HTTP request
 * is inspected to determine the content type.
 * <p/>
 * The simplest evaluation sets the content type to "application/x-www-form-urlencoded" if this is
 * a POST or PUT HTTP request, unless any request parameter value is determined to have multiple
 * parts, the the content type will be "multipart/form-data".
 * <p/>
 * 
 * @param defaultContentType the default content/media type to use when the content type cannot be
 *        determined from this HTTP request.
 * @return a MediaType for the value of the HTTP Content-Type header as determined from this HTTP
 *         request.
 * @see #getHeaders()
 * @see org.springframework.http.HttpHeaders#getContentType()
 * @see org.springframework.http.MediaType
 */
protected MediaType determineContentType(final MediaType defaultContentType) {
  MediaType contentType = getHeaders().getContentType();

  // if the content type HTTP header was not explicitly set, try to determine the media type from
  // the content body
  // of the HTTP request
  if (contentType == null) {
    if (isPost() || isPut()) {
      OUT: for (final String name : getParameters().keySet()) {
        for (final Object value : getParameters().get(name)) {
          if (value != null && !(value instanceof String)) {
            contentType = MediaType.MULTIPART_FORM_DATA;
            break OUT;
          }
        }
      }

      // since this is a POST/PUT HTTP request, default the content/media type to
      // "application/x-www-form-urlencoded"
      contentType = ObjectUtils.defaultIfNull(contentType, MediaType.APPLICATION_FORM_URLENCODED);
    } else {
      // NOTE the "Content-Type" HTTP header is not applicable to GET/DELETE and other methods of
      // HTTP requests
      // since there is typically no content (media/payload/request body/etc) to send. Any request
      // parameters
      // are encoded in the URL as query parameters.
    }
  }

  return ObjectUtils.defaultIfNull(contentType, defaultContentType);
}
 
開發者ID:ampool,項目名稱:monarch,代碼行數:50,代碼來源:ClientHttpRequest.java


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