/** * Predicts the media type of the current fileEntity. * * @return predicted {@link MediaType}. */ protected MediaType predictMediaType() { return predictMediaType(getFileEntity()); }
/** * Sets the {@link MediaType} and fileEntity for this {@link FormDataBodyPart}. * * @param fileEntity the entity of this body part. * @param mediaType the media type. */ public void setFileEntity(final File fileEntity, final MediaType mediaType) { super.setMediaType(mediaType); super.setEntity(fileEntity); this.fileEntity = fileEntity; if (fileEntity != null) { FormDataContentDisposition.FormDataContentDispositionBuilder builder = FormDataContentDisposition.name(getName()); builder.fileName(fileEntity.getName()); if (fileEntity.exists()) { builder.size(fileEntity.length()); builder.modificationDate(new Date(fileEntity.lastModified())); } setFormDataContentDisposition(builder.build()); } }
/** * Predicts the media type of the provided {@link File}. * * @param file the file from which the media type is predicted. * @return predicted {@link MediaType}. */ protected MediaType predictMediaType(final File file) { return getPredictor().getMediaTypeFromFile(file); }
/** * Sets the fileEntity for this {@link FormDataBodyPart}. * * @param fileEntity the entity of this {@link FormDataBodyPart}. */ public void setFileEntity(final File fileEntity) { this.setFileEntity(fileEntity, predictMediaType()); }
public static UploadResponse uploadFile(WebTarget target, Path file, Path tagsFile) { assertThat(Files.exists(file), is(true)); // MediaType of the body part will be derived from the file. FileDataBodyPart filePart = new FileDataBodyPart("file", file.toFile(), MediaType.APPLICATION_OCTET_STREAM_TYPE); FormDataMultiPart mp = new FormDataMultiPart(); mp.bodyPart(filePart); if (tagsFile != null) { FileDataBodyPart tagsFilePart = new FileDataBodyPart("tags", tagsFile.toFile(), MediaType.APPLICATION_OCTET_STREAM_TYPE); mp.bodyPart(tagsFilePart); } if (staticLogger.isDebugEnabled()) { staticLogger.debug("Rest response: {}", restCall(target, "/_upload", mp, String.class, debugOption)); } return restCall(target, "/_upload", mp, UploadResponse.class, Collections.emptyMap()); } }
/** * Adds an attachment from a {@link File}. * * @param file a file to attach * @return this builder */ public MultipartBuilder attachment(File file) { return bodyPart(new FileDataBodyPart(ATTACHMENT_NAME, file)); }
/** * Constructs the body part with all the attributes set for its proper * function. If this constructor is used to construct the body part then it * is not required to set any other attributes for proper behavior. * * @param name the name of body part. * @param fileEntity the file that represents the entity. * @param mediaType the {@link MediaType} of the body part. * @throws java.lang.IllegalArgumentException if the fileEntity is {@code null}. */ public FileDataBodyPart(final String name, final File fileEntity, final MediaType mediaType) throws IllegalArgumentException { super(); super.setName(name); if (mediaType != null) { setFileEntity(fileEntity, mediaType); } else { setFileEntity(fileEntity, predictMediaType(fileEntity)); } }
public void attachment(String attachment) { File file = file(attachment); this.attachments.bodyPart(new FileDataBodyPart(file.getName(), file, APPLICATION_OCTET_STREAM_TYPE)); }
/** * Sets the fileEntity for this {@link FormDataBodyPart}. * * @param fileEntity the entity of this {@link FormDataBodyPart}. */ public void setFileEntity(final File fileEntity) { this.setFileEntity(fileEntity, predictMediaType()); }
/** * Predicts the media type of the current fileEntity. * * @return predicted {@link MediaType}. */ protected MediaType predictMediaType() { return predictMediaType(getFileEntity()); }
/** * Sets the {@link MediaType} and fileEntity for this {@link FormDataBodyPart}. * * @param fileEntity the entity of this body part. * @param mediaType the media type. */ public void setFileEntity(final File fileEntity, final MediaType mediaType) { super.setMediaType(mediaType); super.setEntity(fileEntity); this.fileEntity = fileEntity; if (fileEntity != null) { FormDataContentDisposition.FormDataContentDispositionBuilder builder = FormDataContentDisposition.name(getName()); builder.fileName(fileEntity.getName()); if (fileEntity.exists()) { builder.size(fileEntity.length()); builder.modificationDate(new Date(fileEntity.lastModified())); } setFormDataContentDisposition(builder.build()); } }
/** * Predicts the media type of the provided {@link File}. * * @param file the file from which the media type is predicted. * @return predicted {@link MediaType}. */ protected MediaType predictMediaType(final File file) { return getPredictor().getMediaTypeFromFile(file); }
public void attachment(String attachment) { File file = file(attachment); this.attachments.bodyPart(new FileDataBodyPart(file.getName(), file, APPLICATION_OCTET_STREAM_TYPE)); }
/** * Sets the fileEntity for this {@link FormDataBodyPart}. * * @param fileEntity the entity of this {@link FormDataBodyPart}. */ public void setFileEntity(final File fileEntity) { this.setFileEntity(fileEntity, predictMediaType()); }
/** * Predicts the media type of the current fileEntity. * * @return predicted {@link MediaType}. */ protected MediaType predictMediaType() { return predictMediaType(getFileEntity()); }
/** * Sets the {@link MediaType} and fileEntity for this {@link FormDataBodyPart}. * * @param fileEntity the entity of this body part. * @param mediaType the media type. */ public void setFileEntity(final File fileEntity, final MediaType mediaType) { super.setMediaType(mediaType); super.setEntity(fileEntity); this.fileEntity = fileEntity; if (fileEntity != null) { FormDataContentDisposition.FormDataContentDispositionBuilder builder = FormDataContentDisposition.name(getName()); builder.fileName(fileEntity.getName()); if (fileEntity.exists()) { builder.size(fileEntity.length()); builder.modificationDate(new Date(fileEntity.lastModified())); } setFormDataContentDisposition(builder.build()); } }
/** * Predicts the media type of the provided {@link File}. * * @param file the file from which the media type is predicted. * @return predicted {@link MediaType}. */ protected MediaType predictMediaType(final File file) { return getPredictor().getMediaTypeFromFile(file); }
public Response uploadFile(final String file_path) { final FileDataBodyPart filePart = new FileDataBodyPart("file", new File(file_path)); final FormDataMultiPart multiPart = new FormDataMultiPart(); multiPart.bodyPart(filePart); final Response resp = fileUploadService.uploadFile(multiPart); return resp; } }
/** * Sets the fileEntity for this {@link FormDataBodyPart}. * * @param fileEntity the entity of this {@link FormDataBodyPart}. */ public void setFileEntity(final File fileEntity) { this.setFileEntity(fileEntity, predictMediaType()); }
/** * Predicts the media type of the current fileEntity. * * @return predicted {@link MediaType}. */ protected MediaType predictMediaType() { return predictMediaType(getFileEntity()); }