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);
}
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());
}
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());
}
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);
}
}
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);
}
}
Aggregations