public static VariableValueDto fromFormPart(String type, FormPart binaryDataFormPart) { VariableValueDto dto = new VariableValueDto(); dto.type = type; dto.value = binaryDataFormPart.getBinaryContent(); if (ValueType.FILE.getName().equals(fromRestApiTypeName(type))) { String contentType = binaryDataFormPart.getContentType(); if (contentType == null) { contentType = MediaType.APPLICATION_OCTET_STREAM; } dto.valueInfo = new HashMap<String, Object>(); dto.valueInfo.put(FileValueType.VALUE_INFO_FILE_NAME, binaryDataFormPart.getFileName()); MimeType mimeType = null; try { mimeType = new MimeType(contentType); } catch (MimeTypeParseException e) { throw new RestException(Status.BAD_REQUEST, "Invalid mime type given"); } dto.valueInfo.put(FileValueType.VALUE_INFO_FILE_MIME_TYPE, mimeType.getBaseType()); String encoding = mimeType.getParameter("encoding"); if (encoding != null) { dto.valueInfo.put(FileValueType.VALUE_INFO_FILE_ENCODING, encoding); } String transientString = mimeType.getParameter("transient"); boolean isTransient = Boolean.parseBoolean(transientString); if (isTransient) { dto.valueInfo.put(AbstractValueTypeImpl.VALUE_INFO_TRANSIENT, isTransient); } } return dto; }
public static VariableValueDto fromFormPart(String type, FormPart binaryDataFormPart) { VariableValueDto dto = new VariableValueDto(); dto.type = type; dto.value = binaryDataFormPart.getBinaryContent(); if (ValueType.FILE.getName().equals(fromRestApiTypeName(type))) { String contentType = binaryDataFormPart.getContentType(); if (contentType == null) { contentType = MediaType.APPLICATION_OCTET_STREAM; } dto.valueInfo = new HashMap<String, Object>(); dto.valueInfo.put(FileValueType.VALUE_INFO_FILE_NAME, binaryDataFormPart.getFileName()); MimeType mimeType = null; try { mimeType = new MimeType(contentType); } catch (MimeTypeParseException e) { throw new RestException(Status.BAD_REQUEST, "Invalid mime type given"); } dto.valueInfo.put(FileValueType.VALUE_INFO_FILE_MIME_TYPE, mimeType.getBaseType()); String encoding = mimeType.getParameter("encoding"); if (encoding != null) { dto.valueInfo.put(FileValueType.VALUE_INFO_FILE_ENCODING, encoding); } String transientString = mimeType.getParameter("transient"); boolean isTransient = Boolean.parseBoolean(transientString); if (isTransient) { dto.valueInfo.put(AbstractValueTypeImpl.VALUE_INFO_TRANSIENT, isTransient); } } return dto; }
public static VariableValueDto fromFormPart(String type, FormPart binaryDataFormPart) { VariableValueDto dto = new VariableValueDto(); dto.type = type; dto.value = binaryDataFormPart.getBinaryContent(); if (ValueType.FILE.getName().equals(fromRestApiTypeName(type))) { String contentType = binaryDataFormPart.getContentType(); if (contentType == null) { contentType = MediaType.APPLICATION_OCTET_STREAM; } dto.valueInfo = new HashMap<String, Object>(); dto.valueInfo.put(FileValueType.VALUE_INFO_FILE_NAME, binaryDataFormPart.getFileName()); MimeType mimeType = null; try { mimeType = new MimeType(contentType); } catch (MimeTypeParseException e) { throw new RestException(Status.BAD_REQUEST, "Invalid mime type given"); } dto.valueInfo.put(FileValueType.VALUE_INFO_FILE_MIME_TYPE, mimeType.getBaseType()); String encoding = mimeType.getParameter("encoding"); if (encoding != null) { dto.valueInfo.put(FileValueType.VALUE_INFO_FILE_ENCODING, encoding); } String transientString = mimeType.getParameter("transient"); boolean isTransient = Boolean.parseBoolean(transientString); if (isTransient) { dto.valueInfo.put(AbstractValueTypeImpl.VALUE_INFO_TRANSIENT, isTransient); } } return dto; }