Java Code Examples for org.glassfish.jersey.media.multipart.FormDataMultiPart#setMediaType()

The following examples show how to use org.glassfish.jersey.media.multipart.FormDataMultiPart#setMediaType() . 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: MattermostClient.java    From mattermost4j with Apache License 2.0 6 votes vote down vote up
@Override
public ApiResponse<FileUploadResult> uploadFile(String channelId, Path... filePaths)
    throws IOException {

  if (filePaths.length == 0) {
    throw new IllegalArgumentException("At least one filePath required.");
  }

  FormDataMultiPart multiPart = new FormDataMultiPart();
  multiPart.setMediaType(MediaType.MULTIPART_FORM_DATA_TYPE);

  for (Path filePath : filePaths) {
    FileDataBodyPart body = new FileDataBodyPart("files", filePath.toFile());
    multiPart.bodyPart(body);
  }
  multiPart.field("channel_id", channelId);

  return doApiPostMultiPart(getFilesRoute(), multiPart, FileUploadResult.class);
}
 
Example 2
Source File: MattermostClient.java    From mattermost4j with Apache License 2.0 5 votes vote down vote up
@Override
public ApiResponse<Boolean> setTeamIcon(String teamId, Path iconFilePath) {
  FormDataMultiPart multiPart = new FormDataMultiPart();
  multiPart.setMediaType(MediaType.MULTIPART_FORM_DATA_TYPE);

  FileDataBodyPart body = new FileDataBodyPart("image", iconFilePath.toFile());
  multiPart.bodyPart(body);

  return doApiPostMultiPart(getTeamIconRoute(teamId), multiPart).checkStatusOk();
}
 
Example 3
Source File: MattermostClient.java    From mattermost4j with Apache License 2.0 5 votes vote down vote up
@Override
public ApiResponse<Boolean> uploadLicenseFile(Path licenseFile) {
  FormDataMultiPart multiPart = new FormDataMultiPart();
  multiPart.setMediaType(MediaType.MULTIPART_FORM_DATA_TYPE);

  FileDataBodyPart body = new FileDataBodyPart("license", licenseFile.toFile());
  multiPart.bodyPart(body);

  return doApiPostMultiPart("/license", multiPart).checkStatusOk();
}
 
Example 4
Source File: MattermostClient.java    From mattermost4j with Apache License 2.0 5 votes vote down vote up
@Override
public ApiResponse<Boolean> uploadSamlIdpCertificate(Path dataFile, String fileName) {
  FormDataMultiPart multiPart = new FormDataMultiPart();
  multiPart.setMediaType(MediaType.MULTIPART_FORM_DATA_TYPE);

  FileDataBodyPart body = new FileDataBodyPart("certificate", dataFile.toFile());
  multiPart.bodyPart(body);

  return doApiPostMultiPart(getSamlRoute() + "/certificate/idp", multiPart).checkStatusOk();
}
 
Example 5
Source File: MattermostClient.java    From mattermost4j with Apache License 2.0 5 votes vote down vote up
@Override
public ApiResponse<Boolean> uploadSamlPublicCertificate(Path dataFile, String fileName) {
  FormDataMultiPart multiPart = new FormDataMultiPart();
  multiPart.setMediaType(MediaType.MULTIPART_FORM_DATA_TYPE);

  FileDataBodyPart body = new FileDataBodyPart("certificate", dataFile.toFile());
  multiPart.bodyPart(body);

  return doApiPostMultiPart(getSamlRoute() + "/certificate/public", multiPart).checkStatusOk();
}
 
Example 6
Source File: MattermostClient.java    From mattermost4j with Apache License 2.0 5 votes vote down vote up
@Override
public ApiResponse<Boolean> uploadSamlPrivateCertificate(Path dataFile, String fileName) {
  FormDataMultiPart multiPart = new FormDataMultiPart();
  multiPart.setMediaType(MediaType.MULTIPART_FORM_DATA_TYPE);

  FileDataBodyPart body = new FileDataBodyPart("certificate", dataFile.toFile());
  multiPart.bodyPart(body);

  return doApiPostMultiPart(getSamlRoute() + "/certificate/private", multiPart).checkStatusOk();
}
 
Example 7
Source File: MattermostClient.java    From mattermost4j with Apache License 2.0 5 votes vote down vote up
@Override
public ApiResponse<Boolean> uploadBrandImage(Path dataFile) {
  FormDataMultiPart multiPart = new FormDataMultiPart();
  multiPart.setMediaType(MediaType.MULTIPART_FORM_DATA_TYPE);

  FileDataBodyPart body = new FileDataBodyPart("image", dataFile.toFile());
  multiPart.bodyPart(body);

  return doApiPostMultiPart(getBrandImageRoute(), multiPart).checkStatusOk();
}
 
Example 8
Source File: MattermostClient.java    From mattermost4j with Apache License 2.0 5 votes vote down vote up
@Override
public ApiResponse<Emoji> createEmoji(Emoji emoji, Path imageFile) {
  FormDataMultiPart multiPart = new FormDataMultiPart();
  multiPart.setMediaType(MediaType.MULTIPART_FORM_DATA_TYPE);

  FileDataBodyPart body = new FileDataBodyPart("image", imageFile.toFile());
  multiPart.bodyPart(body);

  multiPart.field("emoji", emoji, MediaType.APPLICATION_JSON_TYPE);

  return doApiPostMultiPart(getEmojisRoute(), multiPart, Emoji.class);
}
 
Example 9
Source File: MattermostClient.java    From mattermost4j with Apache License 2.0 5 votes vote down vote up
@Override
public ApiResponse<PluginManifest> uploadPlugin(Path plugin, boolean force) {
  FormDataMultiPart multiPart = new FormDataMultiPart();
  multiPart.setMediaType(MediaType.MULTIPART_FORM_DATA_TYPE);

  FileDataBodyPart body = new FileDataBodyPart("plugin", plugin.toFile());
  multiPart.bodyPart(body);

  multiPart.field("force", force, MediaType.APPLICATION_JSON_TYPE);

  return doApiPostMultiPart(getPluginsRoute(), multiPart, PluginManifest.class);
}