Search in sources :

Example 31 with ObjectMetadata

use of com.ibm.watson.visual_recognition.v4.model.ObjectMetadata in project goobi-workflow by intranda.

the class S3FileUtils method uploadFile.

@Override
public void uploadFile(InputStream in, Path dest, Long contentLength) throws IOException {
    if (getPathStorageType(dest) == StorageType.LOCAL) {
        nio.uploadFile(in, dest);
        return;
    }
    ObjectMetadata om = new ObjectMetadata();
    om.setContentType(Files.probeContentType(dest));
    om.setContentLength(contentLength);
    // use regular put method if file is smaller than 4gb
    try {
        // use multipart upload for larger files larger than 1GB
        Upload upload = transferManager.upload(getBucket(), path2Key(dest), in, om);
        upload.waitForCompletion();
    } catch (AmazonClientException | InterruptedException e) {
        throw new IOException(e);
    }
}
Also used : AmazonClientException(com.amazonaws.AmazonClientException) Upload(com.amazonaws.services.s3.transfer.Upload) IOException(java.io.IOException) ObjectMetadata(com.amazonaws.services.s3.model.ObjectMetadata)

Example 32 with ObjectMetadata

use of com.ibm.watson.visual_recognition.v4.model.ObjectMetadata in project micronaut-aws-sdk by agorapulse.

the class SimpleStorageServiceTest method buildMetadata.

private static ObjectMetadata buildMetadata() {
    ObjectMetadata objectMetadata = new ObjectMetadata();
    objectMetadata.setContentLength(SAMPLE_CONTENT.length());
    objectMetadata.setContentType("text/plain");
    objectMetadata.setContentDisposition("bar.baz");
    return objectMetadata;
}
Also used : ObjectMetadata(com.amazonaws.services.s3.model.ObjectMetadata)

Example 33 with ObjectMetadata

use of com.ibm.watson.visual_recognition.v4.model.ObjectMetadata 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 34 with ObjectMetadata

use of com.ibm.watson.visual_recognition.v4.model.ObjectMetadata in project entrada by SIDN.

the class S3FileManagerImpl method uploadFile.

private boolean uploadFile(File src, S3Details dstDetails, boolean archive) {
    PutObjectRequest request = new PutObjectRequest(dstDetails.getBucket(), FileUtil.appendPath(dstDetails.getKey(), src.getName()), src);
    ObjectMetadata meta = new ObjectMetadata();
    if (archive) {
        meta.setHeader(Headers.STORAGE_CLASS, StorageClass.fromValue(StringUtils.upperCase(archiveStorageClass)));
    }
    if (encrypt) {
        meta.setSSEAlgorithm(ObjectMetadata.AES_256_SERVER_SIDE_ENCRYPTION);
    }
    request.setMetadata(meta);
    try {
        amazonS3.putObject(request);
        return true;
    } catch (Exception e) {
        log.error("Error while uploading file: {}", src, e);
    }
    return false;
}
Also used : ObjectMetadata(com.amazonaws.services.s3.model.ObjectMetadata) PutObjectRequest(com.amazonaws.services.s3.model.PutObjectRequest) URISyntaxException(java.net.URISyntaxException) AmazonServiceException(com.amazonaws.AmazonServiceException)

Example 35 with ObjectMetadata

use of com.ibm.watson.visual_recognition.v4.model.ObjectMetadata in project TDP by hyeyoungs.

the class FileService method uploadImage.

public String uploadImage(MultipartFile file) throws IOException {
    String fileName = createFileName(file.getOriginalFilename());
    String url;
    ObjectMetadata objectMetadata = new ObjectMetadata();
    objectMetadata.setContentLength(file.getSize());
    objectMetadata.setContentType(file.getContentType());
    try (InputStream inputStream = file.getInputStream()) {
        uploadOnS3(fileName, inputStream, objectMetadata);
        url = defaultUri + fileName;
    } catch (IOException ioe) {
        url = null;
    }
    return url;
}
Also used : InputStream(java.io.InputStream) IOException(java.io.IOException) ObjectMetadata(com.amazonaws.services.s3.model.ObjectMetadata)

Aggregations

ObjectMetadata (com.amazonaws.services.s3.model.ObjectMetadata)566 PutObjectRequest (com.amazonaws.services.s3.model.PutObjectRequest)191 ByteArrayInputStream (java.io.ByteArrayInputStream)157 Test (org.junit.Test)143 IOException (java.io.IOException)101 InputStream (java.io.InputStream)80 File (java.io.File)62 AmazonClientException (com.amazonaws.AmazonClientException)61 AmazonServiceException (com.amazonaws.AmazonServiceException)61 S3Object (com.amazonaws.services.s3.model.S3Object)59 AmazonS3 (com.amazonaws.services.s3.AmazonS3)54 Date (java.util.Date)46 S3FileTransferRequestParamsDto (org.finra.herd.model.dto.S3FileTransferRequestParamsDto)34 GetObjectMetadataRequest (com.amazonaws.services.s3.model.GetObjectMetadataRequest)33 PutObjectResult (com.amazonaws.services.s3.model.PutObjectResult)32 GetObjectRequest (com.amazonaws.services.s3.model.GetObjectRequest)30 AmazonS3Exception (com.amazonaws.services.s3.model.AmazonS3Exception)29 Upload (com.amazonaws.services.s3.transfer.Upload)26 SdkClientException (com.amazonaws.SdkClientException)24 CopyObjectRequest (com.amazonaws.services.s3.model.CopyObjectRequest)24