use of com.ibm.watson.visual_recognition.v4.model.ObjectMetadata in project iudx-resource-server by datakaveri.
the class S3FileOpsHelper method s3Upload.
public void s3Upload(File file, String objectKey, Handler<AsyncResult<JsonObject>> handler) {
DefaultAWSCredentialsProviderChain credentialProviderChain = new DefaultAWSCredentialsProviderChain();
try {
AmazonS3 s3Client = AmazonS3ClientBuilder.standard().withRegion(clientRegion).withCredentials(credentialProviderChain).build();
TransferManager tm = TransferManagerBuilder.standard().withS3Client(s3Client).build();
ObjectMetadata objectMetadata = new ObjectMetadata();
objectMetadata.setContentDisposition("attachment; filename=" + file.getName());
objectMetadata.setContentLength(file.length());
// TransferManager processes all transfers asynchronously,
// so this call returns immediately.
Upload upload = tm.upload(bucketName, objectKey, new FileInputStream(file), objectMetadata);
LOGGER.info("Object upload started");
// upload.addProgressListener(uploadProgressListener);
upload.waitForCompletion();
LOGGER.info("Object upload complete");
ZonedDateTime zdt = ZonedDateTime.now();
zdt = zdt.plusDays(1);
Long expiry = zdt.toEpochSecond() * 1000;
JsonObject result = new JsonObject().put("s3_url", generatePreSignedUrl(expiry, objectKey)).put("expiry", zdt.toLocalDateTime().toString()).put("object_id", objectKey);
handler.handle(Future.succeededFuture(result));
} catch (AmazonServiceException e) {
// The call was transmitted successfully, but Amazon S3 couldn't process
// it, so it returned an error response.
LOGGER.error(e);
handler.handle(Future.failedFuture(e));
} catch (AmazonClientException e) {
LOGGER.error(e);
handler.handle(Future.failedFuture(e));
} catch (InterruptedException e) {
LOGGER.error(e);
handler.handle(Future.failedFuture(e));
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
handler.handle(Future.failedFuture(e));
}
}
use of com.ibm.watson.visual_recognition.v4.model.ObjectMetadata in project geowebcache by GeoWebCache.
the class S3BlobStore method delete.
@Override
public boolean delete(TileObject obj) throws StorageException {
final String key = keyBuilder.forTile(obj);
// don't bother for the extra call if there are no listeners
if (listeners.isEmpty()) {
return s3Ops.deleteObject(key);
}
ObjectMetadata oldObj = s3Ops.getObjectMetadata(key);
if (oldObj == null) {
return false;
}
s3Ops.deleteObject(key);
obj.setBlobSize((int) oldObj.getContentLength());
listeners.sendTileDeleted(obj);
return true;
}
use of com.ibm.watson.visual_recognition.v4.model.ObjectMetadata in project geowebcache by GeoWebCache.
the class S3BlobStore method put.
@Override
public void put(TileObject obj) throws StorageException {
final Resource blob = obj.getBlob();
checkNotNull(blob);
checkNotNull(obj.getBlobFormat());
final String key = keyBuilder.forTile(obj);
ObjectMetadata objectMetadata = new ObjectMetadata();
objectMetadata.setContentLength(blob.getSize());
String blobFormat = obj.getBlobFormat();
String mimeType;
try {
mimeType = MimeType.createFromFormat(blobFormat).getMimeType();
} catch (MimeException me) {
throw new RuntimeException(me);
}
objectMetadata.setContentType(mimeType);
// don't bother for the extra call if there are no listeners
final boolean existed;
ObjectMetadata oldObj;
if (listeners.isEmpty()) {
existed = false;
oldObj = null;
} else {
oldObj = s3Ops.getObjectMetadata(key);
existed = oldObj != null;
}
final ByteArrayInputStream input = toByteArray(blob);
PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, key, input, objectMetadata).withCannedAcl(acl);
log.trace(log.isTraceEnabled() ? ("Storing " + key) : "");
s3Ops.putObject(putObjectRequest);
putParametersMetadata(obj.getLayerName(), obj.getParametersId(), obj.getParameters());
/*
* This is important because listeners may be tracking tile existence
*/
if (!listeners.isEmpty()) {
if (existed) {
long oldSize = oldObj.getContentLength();
listeners.sendTileUpdated(obj, oldSize);
} else {
listeners.sendTileStored(obj);
}
}
}
use of com.ibm.watson.visual_recognition.v4.model.ObjectMetadata in project geowebcache by GeoWebCache.
the class S3Ops method putProperties.
public void putProperties(String resourceKey, Properties properties) throws StorageException {
ByteArrayOutputStream out = new ByteArrayOutputStream();
try {
properties.store(out, "");
} catch (IOException e) {
throw new RuntimeException(e);
}
byte[] bytes = out.toByteArray();
ObjectMetadata objectMetadata = new ObjectMetadata();
objectMetadata.setContentLength(bytes.length);
objectMetadata.setContentType("text/plain");
InputStream in = new ByteArrayInputStream(bytes);
PutObjectRequest putReq = new PutObjectRequest(bucketName, resourceKey, in, objectMetadata);
putObject(putReq);
}
use of com.ibm.watson.visual_recognition.v4.model.ObjectMetadata in project mojito by box.
the class S3BlobStorage method put.
@Override
public void put(String name, String content, Retention retention) {
byte[] bytes = content.getBytes(StandardCharsets.UTF_8);
ObjectMetadata objectMetadata = new ObjectMetadata();
objectMetadata.setContentType("text/plain");
objectMetadata.setContentEncoding(StandardCharsets.UTF_8.toString());
put(name, bytes, retention, objectMetadata);
}
Aggregations