Search in sources :

Example 1 with FileException

use of com.valdir.jornadaback.services.exceptions.FileException in project jornada-back by ValdirCezar.

the class S3ServiceImpl method uploadFile.

@Override
public URI uploadFile(String fileName, InputStream inputStream, String contentType, Long classId) {
    try {
        var metadata = new ObjectMetadata();
        metadata.setContentType(contentType);
        s3Client.putObject(bucketName + "/classes/classId-" + classId, fileName, inputStream, metadata);
        return s3Client.getUrl(bucketName, fileName).toURI();
    } catch (URISyntaxException e) {
        throw new FileException("Erro ao converter URL para URI");
    }
}
Also used : FileException(com.valdir.jornadaback.services.exceptions.FileException) URISyntaxException(java.net.URISyntaxException) ObjectMetadata(com.amazonaws.services.s3.model.ObjectMetadata)

Example 2 with FileException

use of com.valdir.jornadaback.services.exceptions.FileException in project jornada-back by ValdirCezar.

the class S3ServiceImpl method uploadFile.

@Override
public URI uploadFile(MultipartFile file, Long classId) {
    try {
        String fileName = file.getOriginalFilename();
        verifyExtension(fileName);
        InputStream inputStream = file.getInputStream();
        String contentType = file.getContentType();
        return uploadFile(fileName, inputStream, contentType, classId);
    } catch (IOException e) {
        throw new FileException("Erro de IO" + e.getMessage());
    }
}
Also used : FileException(com.valdir.jornadaback.services.exceptions.FileException) InputStream(java.io.InputStream) IOException(java.io.IOException)

Aggregations

FileException (com.valdir.jornadaback.services.exceptions.FileException)2 ObjectMetadata (com.amazonaws.services.s3.model.ObjectMetadata)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 URISyntaxException (java.net.URISyntaxException)1