Search in sources :

Example 66 with ObjectMetadata

use of com.ibm.watson.visual_recognition.v4.model.ObjectMetadata in project XHuiCloud by sindaZeng.

the class OssService method upload.

/**
 * @param bucketName 存储桶
 * @param fileName 文件名
 * @param stream 文件流
 * @param size 大小
 * @param contextType 类型
 * @return
 * @throws Exception
 */
public PutObjectResult upload(String bucketName, String fileName, InputStream stream, long size, String contextType) throws Exception {
    ObjectMetadata objectMetadata = new ObjectMetadata();
    objectMetadata.setContentLength(size);
    objectMetadata.setContentType(contextType);
    ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(IOUtils.toByteArray(stream));
    return amazonS3.putObject(bucketName, fileName, byteArrayInputStream, objectMetadata);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ObjectMetadata(com.amazonaws.services.s3.model.ObjectMetadata)

Example 67 with ObjectMetadata

use of com.ibm.watson.visual_recognition.v4.model.ObjectMetadata in project kafka-large-message-serde by bakdata.

the class AmazonS3Client method putObject.

@Override
public String putObject(final byte[] bytes, final String bucket, final String key) {
    try (final InputStream content = new ByteArrayInputStream(bytes)) {
        final ObjectMetadata metadata = createMetadata(bytes);
        this.s3.putObject(bucket, key, content, metadata);
        return asURI(bucket, key);
    } catch (final IOException e) {
        throw new SerializationException("Error backing message on S3", e);
    }
}
Also used : SerializationException(org.apache.kafka.common.errors.SerializationException) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException) ObjectMetadata(com.amazonaws.services.s3.model.ObjectMetadata)

Example 68 with ObjectMetadata

use of com.ibm.watson.visual_recognition.v4.model.ObjectMetadata in project kafka-large-message-serde by bakdata.

the class AmazonS3Client method createMetadata.

private static ObjectMetadata createMetadata(final byte[] bytes) {
    final ObjectMetadata metadata = new ObjectMetadata();
    metadata.setContentLength(bytes.length);
    return metadata;
}
Also used : ObjectMetadata(com.amazonaws.services.s3.model.ObjectMetadata)

Example 69 with ObjectMetadata

use of com.ibm.watson.visual_recognition.v4.model.ObjectMetadata in project trino by trinodb.

the class TrinoS3FileSystem method customizePutObjectRequest.

private void customizePutObjectRequest(PutObjectRequest request) {
    if (request.getMetadata() == null) {
        request.setMetadata(new ObjectMetadata());
    }
    if (sseEnabled) {
        switch(sseType) {
            case KMS:
                request.setSSEAwsKeyManagementParams(getSseKeyManagementParams());
                break;
            case S3:
                request.getMetadata().setSSEAlgorithm(ObjectMetadata.AES_256_SERVER_SIDE_ENCRYPTION);
                break;
        }
    }
    request.setCannedAcl(s3AclType.getCannedACL());
    request.setRequesterPays(requesterPaysEnabled);
    request.setStorageClass(s3StorageClass.getS3StorageClass());
}
Also used : ObjectMetadata(com.amazonaws.services.s3.model.ObjectMetadata)

Example 70 with ObjectMetadata

use of com.ibm.watson.visual_recognition.v4.model.ObjectMetadata in project trino by trinodb.

the class TestTrinoS3FileSystem method testEmptyDirectory.

@Test
public void testEmptyDirectory() throws Exception {
    try (TrinoS3FileSystem fs = new TrinoS3FileSystem()) {
        MockAmazonS3 s3 = new MockAmazonS3() {

            @Override
            public ObjectMetadata getObjectMetadata(GetObjectMetadataRequest getObjectMetadataRequest) {
                if (getObjectMetadataRequest.getKey().equals("empty-dir/")) {
                    ObjectMetadata objectMetadata = new ObjectMetadata();
                    objectMetadata.setContentType(S3_DIRECTORY_OBJECT_CONTENT_TYPE);
                    return objectMetadata;
                }
                return super.getObjectMetadata(getObjectMetadataRequest);
            }
        };
        fs.initialize(new URI("s3n://test-bucket/"), new Configuration(false));
        fs.setS3Client(s3);
        FileStatus fileStatus = fs.getFileStatus(new Path("s3n://test-bucket/empty-dir/"));
        assertTrue(fileStatus.isDirectory());
        fileStatus = fs.getFileStatus(new Path("s3n://test-bucket/empty-dir"));
        assertTrue(fileStatus.isDirectory());
    }
}
Also used : Path(org.apache.hadoop.fs.Path) GetObjectMetadataRequest(com.amazonaws.services.s3.model.GetObjectMetadataRequest) FileStatus(org.apache.hadoop.fs.FileStatus) LocatedFileStatus(org.apache.hadoop.fs.LocatedFileStatus) Configuration(org.apache.hadoop.conf.Configuration) ClientConfiguration(com.amazonaws.ClientConfiguration) ObjectMetadata(com.amazonaws.services.s3.model.ObjectMetadata) URI(java.net.URI) Test(org.testng.annotations.Test)

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