Search in sources :

Example 1 with ObjectMetadata

use of com.ibm.watson.visual_recognition.v4.model.ObjectMetadata in project KW-Whole_In_One-Backend by nh0317.

the class FileUploadService method uploadImage.

public String uploadImage(MultipartFile file) {
    String fileName = createFileName(file.getOriginalFilename());
    ObjectMetadata objectMetadata = new ObjectMetadata();
    objectMetadata.setContentType(file.getContentType());
    objectMetadata.setContentLength(file.getSize());
    try (InputStream inputStream = file.getInputStream()) {
        s3Service.uploadFile(inputStream, objectMetadata, fileName);
    } catch (IOException e) {
        throw new IllegalArgumentException(String.format("파일 변환 중 에러가 발생하였습니다 (%s)", file.getOriginalFilename()));
    }
    return s3Service.getFileUrl(fileName);
}
Also used : InputStream(java.io.InputStream) IOException(java.io.IOException) ObjectMetadata(com.amazonaws.services.s3.model.ObjectMetadata)

Example 2 with ObjectMetadata

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

the class ToolTesterS3Client method convertObjectListingToTooltesterLogs.

private List<ToolTesterLog> convertObjectListingToTooltesterLogs(ObjectListing firstListing) {
    ObjectListing listing = firstListing;
    List<S3ObjectSummary> summaries = listing.getObjectSummaries();
    while (listing.isTruncated()) {
        listing = s3.listNextBatchOfObjects(listing);
        summaries.addAll(listing.getObjectSummaries());
    }
    return summaries.stream().map(summary -> {
        ObjectMetadata objectMetadata = s3.getObjectMetadata(bucketName, summary.getKey());
        Map<String, String> userMetadata = objectMetadata.getUserMetadata();
        String filename = getFilenameFromSummary(summary);
        return convertUserMetadataToToolTesterLog(userMetadata, filename);
    }).collect(Collectors.toList());
}
Also used : Arrays(java.util.Arrays) AmazonS3ClientBuilder(com.amazonaws.services.s3.AmazonS3ClientBuilder) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) StandardCharsets(java.nio.charset.StandardCharsets) ObjectListing(com.amazonaws.services.s3.model.ObjectListing) ArrayList(java.util.ArrayList) Regions(com.amazonaws.regions.Regions) IOUtils(org.apache.commons.io.IOUtils) URLEncoder(java.net.URLEncoder) List(java.util.List) ObjectMetadata(com.amazonaws.services.s3.model.ObjectMetadata) S3Object(com.amazonaws.services.s3.model.S3Object) Map(java.util.Map) AmazonS3(com.amazonaws.services.s3.AmazonS3) S3ObjectSummary(com.amazonaws.services.s3.model.S3ObjectSummary) UnsupportedEncodingException(java.io.UnsupportedEncodingException) InputStream(java.io.InputStream) ObjectListing(com.amazonaws.services.s3.model.ObjectListing) S3ObjectSummary(com.amazonaws.services.s3.model.S3ObjectSummary) ObjectMetadata(com.amazonaws.services.s3.model.ObjectMetadata) Map(java.util.Map)

Example 3 with ObjectMetadata

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

the class ToolTesterS3ClientTest method convertUserMetadataToToolTesterLog.

/**
 * Test whether the metadata and filename of an s3 object can be converted into the ToolTesterLog object that the UI reads
 */
@Test
public void convertUserMetadataToToolTesterLog() {
    ObjectMetadata metadata = new ObjectMetadata();
    metadata.setContentType(MediaType.TEXT_PLAIN);
    metadata.addUserMetadata("tool_id", "quay.io/pancancer/pcawg-bwa-mem-workflow");
    metadata.addUserMetadata("version_name", "2.7.0");
    metadata.addUserMetadata("test_file_path", "test1.json");
    metadata.addUserMetadata("runner", "cwltool");
    metadata.setContentLength(5);
    Map<String, String> userMetadata = metadata.getUserMetadata();
    ToolTesterLog toolTesterLog = ToolTesterS3Client.convertUserMetadataToToolTesterLog(userMetadata, "10101011.log");
    Assert.assertEquals("quay.io/pancancer/pcawg-bwa-mem-workflow", toolTesterLog.getToolId());
    Assert.assertEquals("2.7.0", toolTesterLog.getToolVersionName());
    Assert.assertEquals("test1.json", toolTesterLog.getTestFilename());
    Assert.assertEquals("cwltool", toolTesterLog.getRunner());
    Assert.assertEquals("10101011.log", toolTesterLog.getFilename());
}
Also used : ObjectMetadata(com.amazonaws.services.s3.model.ObjectMetadata) Test(org.junit.Test)

Example 4 with ObjectMetadata

use of com.ibm.watson.visual_recognition.v4.model.ObjectMetadata in project beneficiary-fhir-data by CMSgov.

the class DataSetTestUtilities method createPutRequest.

/**
 * @param bucket the {@link Bucket} to place the new object in
 * @param keyPrefix the S3 key prefix to store the new object under
 * @param manifest the {@link DataSetManifest} to push as an object
 * @return a {@link PutObjectRequest} for the specified {@link DataSetManifest}
 */
public static PutObjectRequest createPutRequest(Bucket bucket, String keyPrefix, DataSetManifest manifest) {
    String objectKey = String.format("%s/%d_%s", keyPrefix, manifest.getSequenceId(), "manifest.xml");
    try {
        // Serialize the manifest to a byte array.
        JAXBContext jaxbContext = JAXBContext.newInstance(DataSetManifest.class);
        Marshaller marshaller = jaxbContext.createMarshaller();
        ByteArrayOutputStream manifestOutputStream = new ByteArrayOutputStream();
        marshaller.marshal(manifest, manifestOutputStream);
        byte[] manifestByteArray = manifestOutputStream.toByteArray();
        InputStream manifestInputStream = new ByteArrayInputStream(manifestByteArray);
        // If this isn't specified, the AWS API logs annoying warnings.
        ObjectMetadata manifestMetadata = new ObjectMetadata();
        manifestMetadata.setContentLength(manifestByteArray.length);
        PutObjectRequest request = new PutObjectRequest(bucket.getName(), objectKey, manifestInputStream, manifestMetadata);
        return request;
    } catch (JAXBException e) {
        throw new RuntimeException(e);
    }
}
Also used : Marshaller(javax.xml.bind.Marshaller) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) JAXBException(javax.xml.bind.JAXBException) JAXBContext(javax.xml.bind.JAXBContext) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ObjectMetadata(com.amazonaws.services.s3.model.ObjectMetadata) PutObjectRequest(com.amazonaws.services.s3.model.PutObjectRequest)

Example 5 with ObjectMetadata

use of com.ibm.watson.visual_recognition.v4.model.ObjectMetadata in project beneficiary-fhir-data by CMSgov.

the class DataSetTestUtilities method createPutRequest.

/**
 * @param bucket the {@link Bucket} to place the new object in
 * @param keyPrefix the S3 key prefix to store the new object under
 * @param manifest the {@link DataSetManifest} to create an object for
 * @param manifestEntry the {@link DataSetManifestEntry} to create an object for
 * @param objectContentsUrl a {@link URL} to the data to push as the new object's content
 * @return a {@link PutObjectRequest} for the specified content
 */
public static PutObjectRequest createPutRequest(Bucket bucket, String keyPrefix, DataSetManifest manifest, DataSetManifestEntry manifestEntry, URL objectContentsUrl) {
    String objectKey = String.format("%s/%s", keyPrefix, manifestEntry.getName());
    try {
        // If this isn't specified, the AWS API logs annoying warnings.
        int objectContentLength = objectContentsUrl.openConnection().getContentLength();
        ObjectMetadata objectMetadata = new ObjectMetadata();
        objectMetadata.setContentLength(objectContentLength);
        // create md5chksum on file to be uploaded
        objectMetadata.addUserMetadata("md5chksum", ManifestEntryDownloadTask.computeMD5ChkSum(objectContentsUrl.openStream()));
        PutObjectRequest request = new PutObjectRequest(bucket.getName(), objectKey, objectContentsUrl.openStream(), objectMetadata);
        /*
       * Per https://github.com/aws/aws-sdk-java/issues/427, this is
       * required when PUTing objects from an InputStream (as opposed to a
       * File). Without it, was seeing intermittent errors.
       */
        request.getRequestClientOptions().setReadLimit(objectContentLength + 1);
        return request;
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    } catch (NoSuchAlgorithmException e) {
        throw new ChecksumException("NoSuchAlgorithmException on file " + manifest.getTimestampText() + manifestEntry.getName() + "trying to build md5chksum", e);
    }
}
Also used : ChecksumException(gov.cms.bfd.pipeline.ccw.rif.extract.exceptions.ChecksumException) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) ObjectMetadata(com.amazonaws.services.s3.model.ObjectMetadata) PutObjectRequest(com.amazonaws.services.s3.model.PutObjectRequest)

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