本文整理汇总了Java中org.jboss.resteasy.plugins.providers.multipart.MultipartFormDataInput.getFormDataPart方法的典型用法代码示例。如果您正苦于以下问题:Java MultipartFormDataInput.getFormDataPart方法的具体用法?Java MultipartFormDataInput.getFormDataPart怎么用?Java MultipartFormDataInput.getFormDataPart使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jboss.resteasy.plugins.providers.multipart.MultipartFormDataInput
的用法示例。
在下文中一共展示了MultipartFormDataInput.getFormDataPart方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getBinaryArtifact
import org.jboss.resteasy.plugins.providers.multipart.MultipartFormDataInput; //导入方法依赖的package包/类
@Nonnull
private InputStream getBinaryArtifact(MultipartFormDataInput input) {
if (input == null || input.getParts() == null || input.getParts().isEmpty()) {
throw new IllegalArgumentException("Multipart request is empty");
}
try {
InputStream result;
if (input.getParts().size() == 1) {
InputPart filePart = input.getParts().iterator().next();
result = filePart.getBody(InputStream.class, null);
} else {
result = input.getFormDataPart("file", InputStream.class, null);
}
if (result == null) {
throw new IllegalArgumentException("Can't find a valid 'file' part in the multipart request");
}
return result;
} catch (IOException e) {
throw new IllegalArgumentException("Error while reading multipart request", e);
}
}
示例2: uploadFile
import org.jboss.resteasy.plugins.providers.multipart.MultipartFormDataInput; //导入方法依赖的package包/类
@POST
@Path(PATH_UPLOAD)
@Consumes(MULTIPART_FORM_DATA)
@RequiresJwt
public Response uploadFile(MultipartFormDataInput multipart) {
try {
byte[] data = multipart.getFormDataPart(PARAM_DATA, byte[].class, null);
String bucketName = multipart.getFormDataPart(PARAM_BUCKET_NAME, String.class, null);
String key = multipart.getFormDataPart(PARAM_KEY, String.class, null);
String cannedACL = multipart.getFormDataPart(PARAM_CANNED_ACL, String.class, null);
ObjectMetadata metadata = new ObjectMetadata();
metadata.setContentLength((long) data.length);
this.storageService.uploadFile(S3Request.builder()
.bucketName(bucketName)
.key(key)
.data(IOUtils.buffer(new ByteArrayInputStream(data)))
.metadata(metadata)
.cannedACL(CannedAccessControlList.valueOf(cannedACL))
.build());
return Response.ok("File uploaded successfully!!").build();
} catch (Exception ex) {
throw JaxRSException.builder()
.message(ex.getMessage())
.cause(ex)
.status(STATUS_SERVER_ERROR)
.logException(true)
.build();
}
}