Search in sources :

Example 1 with RequiresJwt

use of com.adeptj.modules.jaxrs.core.jwt.RequiresJwt in project adeptj-modules by AdeptJ.

the class UploadResource method uploadFile.

@POST
@Path(PATH_UPLOAD)
@Consumes(MULTIPART_FORM_DATA)
@RequiresJwt
public Response uploadFile(@MultipartForm FileUploadForm form) {
    try {
        ObjectMetadata metadata = new ObjectMetadata();
        metadata.setContentLength((long) form.getData().length);
        this.storageService.uploadFile(S3Request.builder().bucketName(form.getBucketName()).key(form.getKey()).data(IOUtils.buffer(new ByteArrayInputStream(form.getData()))).metadata(metadata).cannedACL(CannedAccessControlList.valueOf(form.getAccess())).build());
        return Response.ok("File uploaded successfully!!").build();
    } catch (Exception ex) {
        // NOSONAR
        throw JaxRSException.builder().message(ex.getMessage()).cause(ex).status(STATUS_SERVER_ERROR).logException(true).build();
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ObjectMetadata(com.amazonaws.services.s3.model.ObjectMetadata) JaxRSException(com.adeptj.modules.jaxrs.core.JaxRSException) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) RequiresJwt(com.adeptj.modules.jaxrs.core.jwt.RequiresJwt)

Aggregations

JaxRSException (com.adeptj.modules.jaxrs.core.JaxRSException)1 RequiresJwt (com.adeptj.modules.jaxrs.core.jwt.RequiresJwt)1 ObjectMetadata (com.amazonaws.services.s3.model.ObjectMetadata)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 Consumes (javax.ws.rs.Consumes)1 POST (javax.ws.rs.POST)1 Path (javax.ws.rs.Path)1