use of software.amazon.awssdk.services.s3.model.PutObjectRequest in project dataverse by IQSS.
the class S3AccessIO method savePathAsAux.
@Override
public // this method copies a local filesystem Path into this DataAccess Auxiliary location:
void savePathAsAux(Path fileSystemPath, String auxItemTag) throws IOException {
if (!this.canWrite()) {
open(DataAccessOption.WRITE_ACCESS);
}
String destinationKey = getDestinationKey(auxItemTag);
try {
File inputFile = fileSystemPath.toFile();
s3.putObject(new PutObjectRequest(bucketName, destinationKey, inputFile));
} catch (AmazonClientException ase) {
logger.warning("Caught an AmazonServiceException in S3AccessIO.savePathAsAux(): " + ase.getMessage());
throw new IOException("S3AccessIO: Failed to save path as an auxiliary object.");
}
}
use of software.amazon.awssdk.services.s3.model.PutObjectRequest in project dataverse by IQSS.
the class S3AccessIO method savePath.
// StorageIO method for copying a local Path (for ex., a temp file), into this DataAccess location:
@Override
public void savePath(Path fileSystemPath) throws IOException {
long newFileSize = -1;
if (!this.canWrite()) {
open(DataAccessOption.WRITE_ACCESS);
}
try {
File inputFile = fileSystemPath.toFile();
if (dvObject instanceof DataFile) {
s3.putObject(new PutObjectRequest(bucketName, key, inputFile));
newFileSize = inputFile.length();
} else {
throw new IOException("DvObject type other than datafile is not yet supported");
}
} catch (SdkClientException ioex) {
String failureMsg = ioex.getMessage();
if (failureMsg == null) {
failureMsg = "S3AccessIO: Unknown exception occured while uploading a local file into S3Object";
}
throw new IOException(failureMsg);
}
// if it has uploaded successfully, we can reset the size
// of the object:
setSize(newFileSize);
}
use of software.amazon.awssdk.services.s3.model.PutObjectRequest in project sandbox by irof.
the class S3MultipartUploadTest method 比較用の通常のputObject.
@Ignore
@Test
public void 比較用の通常のputObject() throws Exception {
byte[] bytes = new byte[5 * Constants.MB + 1];
ObjectMetadata meta = new ObjectMetadata();
meta.setContentLength(bytes.length);
PutObjectRequest putObjectRequest = new PutObjectRequest("irof-sandbox", "S3MultipartUpload/basic-5MB.dat", new ByteArrayInputStream(bytes), meta);
PutObjectResult result = new AmazonS3Client().putObject(putObjectRequest);
logger.info(result.getETag());
}
use of software.amazon.awssdk.services.s3.model.PutObjectRequest in project sandbox by irof.
the class S3Test method putWithInputStream.
@Test
public void putWithInputStream() throws Exception {
try (InputStream input = new ByteArrayInputStream("test".getBytes(StandardCharsets.UTF_8))) {
ObjectMetadata metaData = new ObjectMetadata();
// 可能なら設定する。設定しなかったらデフォルト値が使われる。
metaData.setContentType("text/plain");
// 設定しなくても計算されるぽいのでスルーでよさげ
// metaData.setContentMD5("CY9rzUYh03PK3k6DJie09g==");
// オプションだけど、できるかぎり設定する。
// 設定しないとWARNログ出ちゃうし、違う値を設定すると例外出る。
// metaData.setContentLength(3);
PutObjectRequest request = new PutObjectRequest("irof-sandbox", "byteFile.txt", input, metaData);
PutObjectResult result = s3.putObject(request);
assertThat(result.getETag(), is("098f6bcd4621d373cade4e832627b4f6"));
}
}
use of software.amazon.awssdk.services.s3.model.PutObjectRequest in project stocator by CODAIT.
the class COSAPIClient method createObject.
@Override
public FSDataOutputStream createObject(String objName, String contentType, Map<String, String> metadata, Statistics statistics) throws IOException {
LOG.debug("Create object {}", objName);
try {
String objNameWithoutBuket = objName;
if (objName.startsWith(mBucket + "/")) {
objNameWithoutBuket = objName.substring(mBucket.length() + 1);
}
if (blockUploadEnabled) {
return new FSDataOutputStream(new COSBlockOutputStream(this, objNameWithoutBuket, new SemaphoredDelegatingExecutor(threadPoolExecutor, blockOutputActiveBlocks, true), partSize, blockFactory, contentType, new WriteOperationHelper(objNameWithoutBuket), metadata), null);
}
if (!contentType.equals(Constants.APPLICATION_DIRECTORY)) {
return new FSDataOutputStream(new COSOutputStream(mBucket, objName, mClient, contentType, metadata, transfers, this), statistics);
} else {
final InputStream im = new InputStream() {
@Override
public int read() throws IOException {
return -1;
}
};
final ObjectMetadata om = new ObjectMetadata();
om.setContentLength(0L);
om.setContentType(contentType);
om.setUserMetadata(metadata);
// Remove the bucket name prefix from key path
if (objName.startsWith(mBucket + "/")) {
objName = objName.substring(mBucket.length() + 1);
}
/*
if (!objName.endsWith("/")) {
objName = objName + "/";
}*/
LOG.debug("bucket: {}, key {}", mBucket, objName);
PutObjectRequest putObjectRequest = new PutObjectRequest(mBucket, objName, im, om);
Upload upload = transfers.upload(putObjectRequest);
upload.waitForUploadResult();
OutputStream fakeStream = new OutputStream() {
@Override
public void write(int b) throws IOException {
}
@Override
public void close() throws IOException {
super.close();
}
};
return new FSDataOutputStream(fakeStream, statistics);
}
} catch (InterruptedException e) {
throw new InterruptedIOException("Interrupted creating " + objName);
} catch (IOException e) {
LOG.error(e.getMessage());
throw e;
}
}
Aggregations