Java Code Examples for com.amazonaws.services.s3.model.ObjectMetadata#addUserMetadata()

The following examples show how to use com.amazonaws.services.s3.model.ObjectMetadata#addUserMetadata() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FileClient.java    From file-service with Apache License 2.0 6 votes vote down vote up
public String putObject(String bucketName, String originFileName, MultipartFile multipartFile) {
    String uuid = UUID.randomUUID().toString().replaceAll("-", "");
    String fileName = FILE + "_" + uuid + "_" + originFileName;
    try {
        InputStream inputStream = multipartFile.getInputStream();
        if (isAwsS3) {
            ObjectMetadata objectMetadata = new ObjectMetadata();
            objectMetadata.addUserMetadata("Content-Type", "application/octet-stream");
            amazonS3.putObject(bucketName, fileName, inputStream, objectMetadata);
        } else {
            minioClient.putObject(bucketName, fileName, inputStream, "application/octet-stream");
        }
    } catch (Exception e) {
        throw new FileUploadException("error.file.upload", e);
    }
    return fileName;
}
 
Example 2
Source File: S3Archiver.java    From chancery with Apache License 2.0 6 votes vote down vote up
private void upload(@NotNull File src, @NotNull String key, @NotNull CallbackPayload payload) {
    log.info("Uploading {} to {} in {}", src, key, bucketName);
    final PutObjectRequest request = new PutObjectRequest(bucketName, key, src);
    final ObjectMetadata metadata = request.getMetadata();
    final String commitId = payload.getAfter();
    if (commitId != null) {
        metadata.addUserMetadata("commit-id", commitId);
    }
    final DateTime timestamp = payload.getTimestamp();
    if (timestamp != null) {
        metadata.addUserMetadata("hook-timestamp",
                ISODateTimeFormat.basicTime().print(timestamp));
    }

    final TimerContext time = uploadTimer.time();
    try {
        s3Client.putObject(request);
    } catch (Exception e) {
        log.error("Couldn't upload to {} in {}", key, bucketName, e);
        throw e;
    } finally {
        time.stop();
    }
    log.info("Uploaded to {} in {}", key, bucketName);
}
 
Example 3
Source File: S3BaseUploadCallable.java    From jobcacher-plugin with MIT License 5 votes vote down vote up
protected ObjectMetadata buildMetadata(File file) throws IOException {
    final ObjectMetadata metadata = new ObjectMetadata();
    metadata.setContentType(Mimetypes.getInstance().getMimetype(file.getName()));
    metadata.setContentLength(file.length());
    metadata.setLastModified(new Date(file.lastModified()));

    if (storageClass != null && !storageClass.isEmpty()) {
        metadata.setHeader("x-amz-storage-class", storageClass);
    }
    if (useServerSideEncryption) {
        metadata.setSSEAlgorithm(ObjectMetadata.AES_256_SERVER_SIDE_ENCRYPTION);
    }

    for (Map.Entry<String, String> entry : userMetadata.entrySet()) {
        final String key = entry.getKey().toLowerCase();
        switch (key) {
            case "cache-control":
                metadata.setCacheControl(entry.getValue());
                break;
            case "expires":
                try {
                    final Date expires = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss z").parse(entry.getValue());
                    metadata.setHttpExpiresDate(expires);
                } catch (ParseException e) {
                    metadata.addUserMetadata(entry.getKey(), entry.getValue());
                }
                break;
            case "content-encoding":
                metadata.setContentEncoding(entry.getValue());
                break;
            case "content-type":
                metadata.setContentType(entry.getValue());
            default:
                metadata.addUserMetadata(entry.getKey(), entry.getValue());
                break;
        }
    }
    return metadata;
}
 
Example 4
Source File: S3Publisher.java    From hollow-reference-implementation with Apache License 2.0 5 votes vote down vote up
public void publishSnapshot(Blob blob) {
    String objectName = getS3ObjectName(blobNamespace, "snapshot", blob.getToVersion());

    ObjectMetadata metadata = new ObjectMetadata();
    metadata.addUserMetadata("to_state", String.valueOf(blob.getToVersion()));
    metadata.setHeader("Content-Length", blob.getFile().length());
    
    uploadFile(blob.getFile(), objectName, metadata);
    
    /// now we update the snapshot index
    updateSnapshotIndex(blob.getToVersion());
}
 
Example 5
Source File: S3Publisher.java    From hollow-reference-implementation with Apache License 2.0 5 votes vote down vote up
public void publishDelta(Blob blob) {
    String objectName = getS3ObjectName(blobNamespace, "delta", blob.getFromVersion());
    
    ObjectMetadata metadata = new ObjectMetadata();
    metadata.addUserMetadata("from_state", String.valueOf(blob.getFromVersion()));
    metadata.addUserMetadata("to_state", String.valueOf(blob.getToVersion()));
    metadata.setHeader("Content-Length", blob.getFile().length());
    
    uploadFile(blob.getFile(), objectName, metadata);
}
 
Example 6
Source File: S3Publisher.java    From hollow-reference-implementation with Apache License 2.0 5 votes vote down vote up
public void publishReverseDelta(Blob blob) {
    String objectName = getS3ObjectName(blobNamespace, "reversedelta", blob.getFromVersion());
    
    ObjectMetadata metadata = new ObjectMetadata();
    metadata.addUserMetadata("from_state", String.valueOf(blob.getFromVersion()));
    metadata.addUserMetadata("to_state", String.valueOf(blob.getToVersion()));
    metadata.setHeader("Content-Length", blob.getFile().length());
    
    uploadFile(blob.getFile(), objectName, metadata);
}
 
Example 7
Source File: PublishExecutor.java    From gocd-s3-artifacts with Apache License 2.0 5 votes vote down vote up
private ObjectMetadata metadata(GoEnvironment env) {
    String tracebackUrl = env.traceBackUrl();
    String user = env.triggeredUser();
    ObjectMetadata objectMetadata = new ObjectMetadata();
    objectMetadata.addUserMetadata(METADATA_USER, user);
    objectMetadata.addUserMetadata(METADATA_TRACEBACK_URL, tracebackUrl);
    objectMetadata.addUserMetadata(COMPLETED, COMPLETED);
    objectMetadata.addUserMetadata(GO_PIPELINE_LABEL, env.get(GO_PIPELINE_LABEL));
    return objectMetadata;
}
 
Example 8
Source File: S3OutputStreamWrapper.java    From streams with Apache License 2.0 5 votes vote down vote up
private void addFile() throws Exception {

    InputStream is = new ByteArrayInputStream(this.outputStream.toByteArray());
    int contentLength = outputStream.size();

    TransferManager transferManager = new TransferManager(amazonS3Client);
    ObjectMetadata metadata = new ObjectMetadata();
    metadata.setExpirationTime(DateTime.now().plusDays(365 * 3).toDate());
    metadata.setContentLength(contentLength);

    metadata.addUserMetadata("writer", "org.apache.streams");

    for (String s : metaData.keySet()) {
      metadata.addUserMetadata(s, metaData.get(s));
    }

    String fileNameToWrite = path + fileName;
    Upload upload = transferManager.upload(bucketName, fileNameToWrite, is, metadata);
    try {
      upload.waitForUploadResult();

      is.close();
      transferManager.shutdownNow(false);
      LOGGER.info("S3 File Close[{} kb] - {}", contentLength / 1024, path + fileName);
    } catch (Exception ignored) {
      LOGGER.trace("Ignoring", ignored);
    }


  }
 
Example 9
Source File: PublishExecutor.java    From gocd-s3-artifacts with Apache License 2.0 5 votes vote down vote up
private ObjectMetadata metadata(GoEnvironment env) {
    String tracebackUrl = env.traceBackUrl();
    String user = env.triggeredUser();
    ObjectMetadata objectMetadata = new ObjectMetadata();
    objectMetadata.addUserMetadata(METADATA_USER, user);
    objectMetadata.addUserMetadata(METADATA_TRACEBACK_URL, tracebackUrl);
    objectMetadata.addUserMetadata(COMPLETED, COMPLETED);
    objectMetadata.addUserMetadata(GO_PIPELINE_LABEL, env.get(GO_PIPELINE_LABEL));
    return objectMetadata;
}
 
Example 10
Source File: S3SinkStreamWriter.java    From Scribengin with GNU Affero General Public License v3.0 5 votes vote down vote up
public S3SinkStreamWriter(S3Folder streamS3Folder) throws IOException {
  this.streamS3Folder = streamS3Folder;
  segmentName = "segment-" + UUID.randomUUID().toString();
  ObjectMetadata metadata = new ObjectMetadata();
  metadata.setContentType("application/binary");
  metadata.addUserMetadata("transaction", "prepare");
  writer = streamS3Folder.createObjectWriter(segmentName, metadata) ;
}
 
Example 11
Source File: S3ClientIntegrationTest.java    From Scribengin with GNU Affero General Public License v3.0 5 votes vote down vote up
@Test
public void testUpdateObjectMetadata() throws IOException, InterruptedException {
  String KEY = "test-update-objec-metadata" ;
  ObjectMetadata metadata = new ObjectMetadata() ;
  metadata.setContentType("text/plain");
  s3Client.createObject(BUCKET_NAME, KEY, new byte[0], metadata);
  metadata = s3Client.getObjectMetadata(BUCKET_NAME, KEY) ;
  metadata.addUserMetadata("transaction", "buffering");
  s3Client.updateObjectMetadata(BUCKET_NAME, KEY, metadata);
  metadata = s3Client.getObjectMetadata(BUCKET_NAME, KEY) ;
  Assert.assertEquals("buffering", metadata.getUserMetaDataOf("transaction"));
}
 
Example 12
Source File: S3SinkStreamWriter.java    From Scribengin with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public void completeCommit() throws Exception {
  ObjectMetadata metadata = writer.getObjectMetadata();
  metadata.addUserMetadata("transaction", "complete");
  streamS3Folder.updateObjectMetadata(segmentName, metadata);
}
 
Example 13
Source File: S3Client.java    From Scribengin with GNU Affero General Public License v3.0 4 votes vote down vote up
public void createObject(String bucketName, String key, InputStream is, ObjectMetadata metadata) {
  s3Client.putObject(new PutObjectRequest(bucketName, key, is, metadata));
  metadata.addUserMetadata("transaction", "test");
}