/** * @return {@code true} if this body part represents a simple, string-based, field value, otherwise {@code false}. */ public boolean isSimple() { return MediaType.TEXT_PLAIN_TYPE.equals(getMediaType()); }
/** * Sets the field value for this body part. This should be called * only on body parts representing simple field values. * * @param value the field value. * @throws IllegalStateException if called on a body part with a media type other than {@code text/plain}. */ public void setValue(String value) { if (!MediaType.TEXT_PLAIN_TYPE.equals(getMediaType())) { throw new IllegalStateException(LocalizationMessages.MEDIA_TYPE_NOT_TEXT_PLAIN()); } setEntity(value); }
/** * Gets the field value for this body part. This should be called only on body parts representing simple field values. * * @return the simple field value. * @throws ProcessingException if an IO error arises during reading the value. * @throws IllegalStateException if called on a body part with a media type other than {@code text/plain} */ public String getValue() { if (!MediaTypes.typeEqual(MediaType.TEXT_PLAIN_TYPE, getMediaType())) { throw new IllegalStateException(LocalizationMessages.MEDIA_TYPE_NOT_TEXT_PLAIN()); } if (getEntity() instanceof BodyPartEntity) { return getValueAs(String.class); } else { return (String) getEntity(); } }
final MediaType mediaType = part != null ? part.getMediaType() : MediaType.TEXT_PLAIN_TYPE; String.class, parameter.getAnnotations(), p.getMediaType());
/** * @return {@code true} if this body part represents a simple, string-based, field value, otherwise {@code false}. */ public boolean isSimple() { return MediaType.TEXT_PLAIN_TYPE.equals(getMediaType()); }
/** * @return {@code true} if this body part represents a simple, string-based, field value, otherwise {@code false}. */ public boolean isSimple() { return MediaType.TEXT_PLAIN_TYPE.equals(getMediaType()); }
/** * @return {@code true} if this body part represents a simple, string-based, field value, otherwise {@code false}. */ public boolean isSimple() { return MediaType.TEXT_PLAIN_TYPE.equals(getMediaType()); }
/** * @return {@code true} if this body part represents a simple, string-based, field value, otherwise {@code false}. */ public boolean isSimple() { return MediaType.TEXT_PLAIN_TYPE.equals(getMediaType()); }
/** * Sets the field value for this body part. This should be called * only on body parts representing simple field values. * * @param value the field value. * @throws IllegalStateException if called on a body part with a media type other than {@code text/plain}. */ public void setValue(String value) { if (!MediaType.TEXT_PLAIN_TYPE.equals(getMediaType())) { throw new IllegalStateException(LocalizationMessages.MEDIA_TYPE_NOT_TEXT_PLAIN()); } setEntity(value); }
/** * Sets the field value for this body part. This should be called * only on body parts representing simple field values. * * @param value the field value. * @throws IllegalStateException if called on a body part with a media type other than {@code text/plain}. */ public void setValue(String value) { if (!MediaType.TEXT_PLAIN_TYPE.equals(getMediaType())) { throw new IllegalStateException(LocalizationMessages.MEDIA_TYPE_NOT_TEXT_PLAIN()); } setEntity(value); }
/** * Sets the field value for this body part. This should be called * only on body parts representing simple field values. * * @param value the field value. * @throws IllegalStateException if called on a body part with a media type other than {@code text/plain}. */ public void setValue(String value) { if (!MediaType.TEXT_PLAIN_TYPE.equals(getMediaType())) { throw new IllegalStateException(LocalizationMessages.MEDIA_TYPE_NOT_TEXT_PLAIN()); } setEntity(value); }
/** * Sets the field value for this body part. This should be called * only on body parts representing simple field values. * * @param value the field value. * @throws IllegalStateException if called on a body part with a media type other than {@code text/plain}. */ public void setValue(String value) { if (!MediaType.TEXT_PLAIN_TYPE.equals(getMediaType())) { throw new IllegalStateException(LocalizationMessages.MEDIA_TYPE_NOT_TEXT_PLAIN()); } setEntity(value); }
@POST @Permissions({ @Permission(value = RolePermission.PORTAL_DOCUMENTATION, acls = RolePermissionAction.CREATE) }) @Path("/upload") @Consumes(MediaType.MULTIPART_FORM_DATA) @Produces("text/plain") public Response upload( @FormDataParam("file") InputStream uploadedInputStream, @FormDataParam("file") FormDataContentDisposition fileDetail, @FormDataParam("file") final FormDataBodyPart body ) { String mediaId = null; if (!body.getMediaType().getType().equals("image")) { throw new UploadUnAuthorized("File format unauthorized " + body.getMediaType().getType()+"/"+body.getMediaType().getSubtype()); } else if (fileDetail.getSize() > this.mediaService.getMediaMaxSize()) { throw new UploadUnAuthorized("Max size achieved " + fileDetail.getSize()); } else { mediaId = mediaService.savePortalMedia(new MediaEntity( uploadedInputStream, body.getMediaType().getType(), body.getMediaType().getSubtype(), fileDetail.getFileName(), fileDetail.getSize() )); } return Response.status(200).entity(mediaId).build(); }
@POST @Consumes(MediaType.MULTIPART_FORM_DATA) public void upload(FormDataMultiPart formParams) { Map<String, List<FormDataBodyPart>> fieldsByName = formParams.getFields(); //Assume i am sending only files with the request for (List<FormDataBodyPart> fields : fieldsByName.values()) { for (FormDataBodyPart field : fields) { InputStream is = field.getEntityAs(InputStream.class); String fileName = field.getName(); field.getMediaType(); //This working fine FormDataContentDisposition f=field.getFormDataContentDisposition(); System.out.println(f.getFileName()); } } }
/** * Gets the field value for this body part. This should be called only on body parts representing simple field values. * * @return the simple field value. * @throws ProcessingException if an IO error arises during reading the value. * @throws IllegalStateException if called on a body part with a media type other than {@code text/plain} */ public String getValue() { if (!MediaTypes.typeEqual(MediaType.TEXT_PLAIN_TYPE, getMediaType())) { throw new IllegalStateException(LocalizationMessages.MEDIA_TYPE_NOT_TEXT_PLAIN()); } if (getEntity() instanceof BodyPartEntity) { return getValueAs(String.class); } else { return (String) getEntity(); } }
/** * Gets the field value for this body part. This should be called only on body parts representing simple field values. * * @return the simple field value. * @throws ProcessingException if an IO error arises during reading the value. * @throws IllegalStateException if called on a body part with a media type other than {@code text/plain} */ public String getValue() { if (!MediaTypes.typeEqual(MediaType.TEXT_PLAIN_TYPE, getMediaType())) { throw new IllegalStateException(LocalizationMessages.MEDIA_TYPE_NOT_TEXT_PLAIN()); } if (getEntity() instanceof BodyPartEntity) { return getValueAs(String.class); } else { return (String) getEntity(); } }
/** * Gets the field value for this body part. This should be called only on body parts representing simple field values. * * @return the simple field value. * @throws ProcessingException if an IO error arises during reading the value. * @throws IllegalStateException if called on a body part with a media type other than {@code text/plain} */ public String getValue() { if (!MediaTypes.typeEqual(MediaType.TEXT_PLAIN_TYPE, getMediaType())) { throw new IllegalStateException(LocalizationMessages.MEDIA_TYPE_NOT_TEXT_PLAIN()); } if (getEntity() instanceof BodyPartEntity) { return getValueAs(String.class); } else { return (String) getEntity(); } }
/** * Gets the field value for this body part. This should be called only on body parts representing simple field values. * * @return the simple field value. * @throws ProcessingException if an IO error arises during reading the value. * @throws IllegalStateException if called on a body part with a media type other than {@code text/plain} */ public String getValue() { if (!MediaTypes.typeEqual(MediaType.TEXT_PLAIN_TYPE, getMediaType())) { throw new IllegalStateException(LocalizationMessages.MEDIA_TYPE_NOT_TEXT_PLAIN()); } if (getEntity() instanceof BodyPartEntity) { return getValueAs(String.class); } else { return (String) getEntity(); } }
@PUT @Consumes(MediaType.MULTIPART_FORM_DATA) @Path("/notifiers/{id}") @Timed public Response addOrUpdateNotifierInfo(@PathParam("id") Long id, @FormDataParam("notifierJarFile") final InputStream inputStream, @FormDataParam("notifierJarFile") final FormDataContentDisposition contentDispositionHeader, @FormDataParam("notifierConfig") final FormDataBodyPart notifierConfig, @Context SecurityContext securityContext) throws IOException { SecurityUtil.checkPermissions(authorizer, securityContext, Notifier.NAMESPACE, id, WRITE); MediaType mediaType = notifierConfig.getMediaType(); LOG.debug("Media type {}", mediaType); if (!mediaType.equals(MediaType.APPLICATION_JSON_TYPE)) { throw new UnsupportedMediaTypeException(mediaType.toString()); } Notifier notifier = notifierConfig.getValueAs(Notifier.class); String jarFileName = uploadJar(inputStream, notifier.getName()); notifier.setJarFileName(jarFileName); Notifier newNotifier = catalogService.addOrUpdateNotifierInfo(id, notifier); return WSUtils.respondEntity(newNotifier, CREATED); }
@POST @Consumes(MediaType.MULTIPART_FORM_DATA) public void upload(FormDataMultiPart formParams){ Map<String, List<FormDataBodyPart>> fieldsByName = formParams.getFields(); for (List<FormDataBodyPart> fields : fieldsByName.values()) { for (FormDataBodyPart field : fields){ // Check if fields are files(If any one knows better solution to check files[] please share your answers) if (StringUtils.equals("files", StringUtils.substringBefore(field.getName(), "["))) { //To read file content InputStream is = field.getEntityAs(InputStream.class); String fileName = field.getName(); field.getMediaType();//File mimeType //To get file details like size,file name,etc FormDataContentDisposition f=field.getFormDataContentDisposition(); System.out.println(f.getFileName()); Note: f.getType() not return the actual file type it returns mime type as form-data to get actual mime type use FormDataBodyPart media type like above. } get other form data like user name else if(StringUtils.equals(field.getName(),"userName")){ System.out.println(field.getValue()); } } } }