Example usage for com.amazonaws.services.s3.model UploadPartRequest setKey

List of usage examples for com.amazonaws.services.s3.model UploadPartRequest setKey

Introduction

In this page you can find the example usage for com.amazonaws.services.s3.model UploadPartRequest setKey.

Prototype

public void setKey(String key) 

Source Link

Document

Sets the key of the initiated multipart upload.

Usage

From source file:c3.ops.priam.aws.S3PartUploader.java

License:Apache License

private Void uploadPart() throws AmazonClientException, BackupRestoreException {
    UploadPartRequest req = new UploadPartRequest();
    req.setBucketName(dataPart.getBucketName());
    req.setKey(dataPart.getS3key());
    req.setUploadId(dataPart.getUploadID());
    req.setPartNumber(dataPart.getPartNo());
    req.setPartSize(dataPart.getPartData().length);
    req.setMd5Digest(SystemUtils.toBase64(dataPart.getMd5()));
    req.setInputStream(new ByteArrayInputStream(dataPart.getPartData()));
    UploadPartResult res = client.uploadPart(req);
    PartETag partETag = res.getPartETag();
    if (!partETag.getETag().equals(SystemUtils.toHex(dataPart.getMd5())))
        throw new BackupRestoreException("Unable to match MD5 for part " + dataPart.getPartNo());
    partETags.add(partETag);//  w w w  .  j  a va  2  s  . c o m
    return null;
}

From source file:com.eucalyptus.objectstorage.providers.s3.S3ProviderClient.java

License:Open Source License

@Override
public UploadPartResponseType uploadPart(UploadPartType request, InputStream dataContent) throws S3Exception {
    String bucketName = request.getBucket();
    String key = request.getKey();

    User requestUser = getRequestUser(request);
    OsgInternalS3Client internalS3Client = null;
    try {/*from  www  .  j  ava  2s .  com*/
        internalS3Client = getS3Client(requestUser);
        AmazonS3Client s3Client = internalS3Client.getS3Client();

        UploadPartResult result;
        UploadPartRequest uploadPartRequest = new UploadPartRequest();
        uploadPartRequest.setBucketName(bucketName);
        uploadPartRequest.setKey(key);
        uploadPartRequest.setInputStream(dataContent);
        uploadPartRequest.setUploadId(request.getUploadId());
        uploadPartRequest.setPartNumber(Integer.valueOf(request.getPartNumber()));
        uploadPartRequest.setMd5Digest(request.getContentMD5());
        uploadPartRequest.setPartSize(Long.valueOf(request.getContentLength()));
        try {
            result = s3Client.uploadPart(uploadPartRequest);
        } catch (AmazonServiceException e) {
            LOG.debug("Error from backend", e);
            throw S3ExceptionMapper.fromAWSJavaSDK(e);
        }
        UploadPartResponseType reply = request.getReply();
        reply.setEtag(result.getETag());
        reply.setLastModified(new Date());
        return reply;
    } catch (AmazonServiceException e) {
        LOG.debug("Error from backend", e);
        throw S3ExceptionMapper.fromAWSJavaSDK(e);
    }
}

From source file:com.netflix.exhibitor.core.backup.s3.S3BackupProvider.java

License:Apache License

private PartETag uploadChunk(byte[] buffer, int bytesRead, InitiateMultipartUploadResult initResponse,
        int index) throws Exception {
    byte[] md5 = S3Utils.md5(buffer, bytesRead);

    UploadPartRequest request = new UploadPartRequest();
    request.setBucketName(initResponse.getBucketName());
    request.setKey(initResponse.getKey());
    request.setUploadId(initResponse.getUploadId());
    request.setPartNumber(index);//from www. jav a2  s  . c  o  m
    request.setPartSize(bytesRead);
    request.setMd5Digest(S3Utils.toBase64(md5));
    request.setInputStream(new ByteArrayInputStream(buffer, 0, bytesRead));

    UploadPartResult response = s3Client.uploadPart(request);
    PartETag partETag = response.getPartETag();
    if (!response.getPartETag().getETag().equals(S3Utils.toHex(md5))) {
        throw new Exception("Unable to match MD5 for part " + index);
    }

    return partETag;
}

From source file:com.upplication.s3fs.S3OutputStream.java

License:Open Source License

private void uploadPart(final InputStream content, final long contentLength, final byte[] checksum,
        final int partNumber, final boolean lastPart) throws IOException {

    if (aborted)//from   ww  w  .  j  a  v  a2s .  co m
        return;

    final UploadPartRequest request = new UploadPartRequest();
    request.setBucketName(objectId.getBucket());
    request.setKey(objectId.getKey());
    request.setUploadId(uploadId);
    request.setPartNumber(partNumber);
    request.setPartSize(contentLength);
    request.setInputStream(content);
    request.setLastPart(lastPart);
    request.setMd5Digest(Base64.encodeAsString(checksum));

    final PartETag partETag = s3.uploadPart(request).getPartETag();
    log.trace("Uploaded part {} with length {} for {}: {}", partETag.getPartNumber(), contentLength, objectId,
            partETag.getETag());
    partETags.add(partETag);

}

From source file:eu.stratosphere.nephele.fs.s3.S3DataOutputStream.java

License:Apache License

private void uploadPartAndFlushBuffer() throws IOException {

    boolean operationSuccessful = false;

    if (this.uploadId == null) {
        this.uploadId = initiateMultipartUpload();
    }/*from  w w  w.j  av  a  2  s  .  c o  m*/

    try {

        if (this.partNumber >= MAX_PART_NUMBER) {
            throw new IOException("Cannot upload any more data: maximum part number reached");
        }

        final InputStream inputStream = new InternalUploadInputStream(this.buf, this.bytesWritten);
        final UploadPartRequest request = new UploadPartRequest();
        request.setBucketName(this.bucket);
        request.setKey(this.object);
        request.setInputStream(inputStream);
        request.setUploadId(this.uploadId);
        request.setPartSize(this.bytesWritten);
        request.setPartNumber(this.partNumber++);

        final UploadPartResult result = this.s3Client.uploadPart(request);
        this.partETags.add(result.getPartETag());

        this.bytesWritten = 0;
        operationSuccessful = true;

    } catch (AmazonServiceException e) {
        throw new IOException(StringUtils.stringifyException(e));
    } finally {
        if (!operationSuccessful) {
            abortUpload();
        }
    }
}