當前位置: 首頁>>代碼示例>>Java>>正文


Java PutObjectRequest類代碼示例

本文整理匯總了Java中com.amazonaws.services.s3.model.PutObjectRequest的典型用法代碼示例。如果您正苦於以下問題:Java PutObjectRequest類的具體用法?Java PutObjectRequest怎麽用?Java PutObjectRequest使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


PutObjectRequest類屬於com.amazonaws.services.s3.model包,在下文中一共展示了PutObjectRequest類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: uploadFile

import com.amazonaws.services.s3.model.PutObjectRequest; //導入依賴的package包/類
/**
 * Upload a file which is in the assets bucket.
 * 
 * @param fileName File name
 * @param file File
 * @param contentType Content type for file
 * @return
 */
public static boolean uploadFile(String fileName, File file, String contentType) {
    try {
        if (S3Module.amazonS3 != null) {
            String bucket = S3Module.s3Bucket;
            ObjectMetadata metaData = new ObjectMetadata();
            if (contentType != null) {
                metaData.setContentType(contentType);
            }
            PutObjectRequest putObj = new PutObjectRequest(bucket,
                    fileName, file);
            putObj.setMetadata(metaData);
            putObj.withCannedAcl(CannedAccessControlList.PublicRead);
            S3Module.amazonS3.putObject(putObj);
            return true;
        } else {
            Logger.error("Could not save because amazonS3 was null");
            return false;
        }
    } catch (Exception e) {
        Logger.error("S3 Upload -" + e.getMessage());
        return false;
    }
}
 
開發者ID:webinerds,項目名稱:s3-proxy-chunk-upload,代碼行數:32,代碼來源:AssetsS3.java

示例2: uploadToS3

import com.amazonaws.services.s3.model.PutObjectRequest; //導入依賴的package包/類
public static void uploadToS3() {
    // upload to s3 bucket
    AWSCredentials awsCredentials = SkillConfig.getAWSCredentials();
    AmazonS3Client s3Client = awsCredentials != null ? new AmazonS3Client(awsCredentials) : new AmazonS3Client();

    File folder = new File("c:/temp/morse/" + DOT + "/mp3/");
    File[] listOfFiles = folder.listFiles();

    for (File file : listOfFiles) {
        if (file.isFile()) {
            if (!s3Client.doesObjectExist("morseskill", DOT + "/" + file.getName())) {
                PutObjectRequest s3Put = new PutObjectRequest("morseskill", DOT + "/" + file.getName(), file).withCannedAcl(CannedAccessControlList.PublicRead);
                s3Client.putObject(s3Put);
                System.out.println("Upload complete: " + file.getName());
            }
            else {
                System.out.println("Skip as " + file.getName() + " already exists.");
            }
        }
    }
}
 
開發者ID:KayLerch,項目名稱:alexa-morser-coder-skill,代碼行數:22,代碼來源:AudioUtils.java

示例3: uploadToAmazonS3

import com.amazonaws.services.s3.model.PutObjectRequest; //導入依賴的package包/類
static public void uploadToAmazonS3(HttpSession session, File fileToUpload) throws S3Exception
{
       try
	{
		AmazonS3 s3client = getS3();
		String bucketName = getDownloadS3Bucket();
		if(!s3client.doesBucketExist(bucketName))
			SagLogger.logError(session, "Does not exist?  S3 Bucket :" + bucketName);

		AccessControlList acl = new AccessControlList();
		acl.grantPermission(GroupGrantee.AllUsers, Permission.Read);
		s3client.putObject(new PutObjectRequest(bucketName, getAPKDownloadFilePathWithFile(fileToUpload.getName()),  fileToUpload).withAccessControlList(acl));

		SagLogger.logInfo(session, "Finished uploading to S3");
	}
	catch (Exception e)
	{
		SagLogger.logException(session, e);
		throw new S3Exception(e);
	}
}
 
開發者ID:benetech,項目名稱:Secure-App-Generator,代碼行數:22,代碼來源:AmazonS3Utils.java

示例4: store

import com.amazonaws.services.s3.model.PutObjectRequest; //導入依賴的package包/類
/**
 * Stores the {@link InputStream} as an object in the S3 bucket.
 *
 * @param keyName The requested key name for the object.
 * @param inStream The {@link InputStream} to write out to an object in S3.
 * @param size The size of the {@link InputStream}.
 * @return A {@link CompletableFuture} that will eventually contain the S3 object key.
 */
@Override
public CompletableFuture<String> store(String keyName, InputStream inStream, long size) {
	final String bucketName = environment.getProperty(Constants.BUCKET_NAME_ENV_VARIABLE);
	final String kmsKey = environment.getProperty(Constants.KMS_KEY_ENV_VARIABLE);
	if (Strings.isNullOrEmpty(bucketName) || Strings.isNullOrEmpty(kmsKey)) {
		API_LOG.warn("No bucket name is specified or no KMS key specified.");
		return CompletableFuture.completedFuture("");
	}

	ObjectMetadata s3ObjectMetadata = new ObjectMetadata();
	s3ObjectMetadata.setContentLength(size);

	PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, keyName, inStream, s3ObjectMetadata)
		.withSSEAwsKeyManagementParams(new SSEAwsKeyManagementParams(kmsKey));

	API_LOG.info("Writing object {} to S3 bucket {}", keyName, bucketName);
	return actOnItem(putObjectRequest);
}
 
開發者ID:CMSgov,項目名稱:qpp-conversion-tool,代碼行數:27,代碼來源:StorageServiceImpl.java

示例5: asynchronousAction

import com.amazonaws.services.s3.model.PutObjectRequest; //導入依賴的package包/類
/**
 * Uses the {@link TransferManager} to upload a file.
 *
 * @param objectToActOn The put request.
 * @return The object key in the bucket.
 */
@Override
protected String asynchronousAction(PutObjectRequest objectToActOn) {
	String returnValue;

	try {
		Upload upload = s3TransferManager.upload(objectToActOn);
		returnValue = upload.waitForUploadResult().getKey();
	} catch (InterruptedException exception) {
		Thread.currentThread().interrupt();
		throw new UncheckedInterruptedException(exception);
	}

	API_LOG.info("Successfully wrote object {} to S3 bucket {}", returnValue, objectToActOn.getBucketName());

	return returnValue;
}
 
開發者ID:CMSgov,項目名稱:qpp-conversion-tool,代碼行數:23,代碼來源:StorageServiceImpl.java

示例6: putObject

import com.amazonaws.services.s3.model.PutObjectRequest; //導入依賴的package包/類
@Override
public PutObjectResult putObject(PutObjectRequest putObjectRequest)
        throws AmazonClientException, AmazonServiceException {
    String blobName = putObjectRequest.getKey();
    DigestInputStream stream = (DigestInputStream) putObjectRequest.getInputStream();

    if (blobs.containsKey(blobName)) {
        throw new AmazonS3Exception("[" + blobName + "] already exists.");
    }

    blobs.put(blobName, stream);

    // input and output md5 hashes need to match to avoid an exception
    String md5 = Base64.encodeAsString(stream.getMessageDigest().digest());
    PutObjectResult result = new PutObjectResult();
    result.setContentMd5(md5);

    return result;
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:20,代碼來源:MockAmazonS3.java

示例7: putObject

import com.amazonaws.services.s3.model.PutObjectRequest; //導入依賴的package包/類
@SuppressWarnings("resource")
@Override
public PutObjectResult putObject(PutObjectRequest putObjectRequest) throws AmazonClientException, AmazonServiceException {
    putObjectRequests.add(putObjectRequest);
    
    S3Object s3Object = new S3Object();
    s3Object.setBucketName(putObjectRequest.getBucketName());
    s3Object.setKey(putObjectRequest.getKey());
    if (putObjectRequest.getFile() != null) {
        try {
            s3Object.setObjectContent(new FileInputStream(putObjectRequest.getFile()));
        } catch (FileNotFoundException e) {
            throw new AmazonServiceException("Cannot store the file object.", e);
        }
    } else {
        s3Object.setObjectContent(putObjectRequest.getInputStream());
    }
    objects.add(s3Object);
    
    PutObjectResult putObjectResult = new PutObjectResult();
    putObjectResult.setETag("3a5c8b1ad448bca04584ecb55b836264");
    return putObjectResult;
}
 
開發者ID:syndesisio,項目名稱:syndesis,代碼行數:24,代碼來源:AmazonS3ClientMock.java

示例8: store

import com.amazonaws.services.s3.model.PutObjectRequest; //導入依賴的package包/類
@Override
public void store(BuildCacheKey key, BuildCacheEntryWriter writer) {
  logger.info("Start storing cache entry '{}' in S3 bucket", key.getHashCode());
  ObjectMetadata meta = new ObjectMetadata();
  meta.setContentType(BUILD_CACHE_CONTENT_TYPE);

  try (ByteArrayOutputStream os = new ByteArrayOutputStream()) {
    writer.writeTo(os);
    meta.setContentLength(os.size());
    try (InputStream is = new ByteArrayInputStream(os.toByteArray())) {
        PutObjectRequest request = getPutObjectRequest(key, meta, is);
        if(this.reducedRedundancy) {
          request.withStorageClass(StorageClass.ReducedRedundancy);
        }
        s3.putObject(request);
    }
  } catch (IOException e) {
    throw new BuildCacheException("Error while storing cache object in S3 bucket", e);
  }
}
 
開發者ID:myniva,項目名稱:gradle-s3-build-cache,代碼行數:21,代碼來源:AwsS3BuildCacheService.java

示例9: createShortUrl

import com.amazonaws.services.s3.model.PutObjectRequest; //導入依賴的package包/類
/**
 * The method creates a short URL code for the given url
 * 
 * @param url
 * @return
 */
public ShortUrl createShortUrl(String url, String code) {

	logger.info("storing the url {} in the bucket {}", url, this.bucket);
	// Create the link for the short code
	if (code == null) {
		code = getObjectCode();
	}
	String loadFile = redirectFile.replace("REPLACE", url);
	byte[] fileContentBytes = loadFile.getBytes(StandardCharsets.UTF_8);
	InputStream fileInputStream = new ByteArrayInputStream(fileContentBytes);
	ObjectMetadata metadata = new ObjectMetadata();
	metadata.setContentType("text/html");
	metadata.addUserMetadata("url", url);
	metadata.setContentLength(fileContentBytes.length);
	PutObjectRequest putObjectRequest = new PutObjectRequest(this.bucket, code, fileInputStream, metadata)
			.withCannedAcl(CannedAccessControlList.PublicRead);
	this.s3Client.putObject(putObjectRequest);
	createDummyRecord(url, code);
	return new ShortUrl(url, code);
}
 
開發者ID:weblegit,項目名稱:urlshortner,代碼行數:27,代碼來源:UrlShortnerService.java

示例10: createEmptyObject

import com.amazonaws.services.s3.model.PutObjectRequest; //導入依賴的package包/類
private void createEmptyObject(final String bucketName, final String objectName)
    throws AmazonClientException, AmazonServiceException {
  final InputStream im = new InputStream() {
    @Override
    public int read() throws IOException {
      return -1;
    }
  };

  final ObjectMetadata om = new ObjectMetadata();
  om.setContentLength(0L);
  if (StringUtils.isNotBlank(serverSideEncryptionAlgorithm)) {
    om.setServerSideEncryption(serverSideEncryptionAlgorithm);
  }
  PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, objectName, im, om);
  putObjectRequest.setCannedAcl(cannedACL);
  s3.putObject(putObjectRequest);
  statistics.incrementWriteOps(1);
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:20,代碼來源:S3AFileSystem.java

示例11: putObject

import com.amazonaws.services.s3.model.PutObjectRequest; //導入依賴的package包/類
@Override
public PutObjectResult putObject(String bucketName, String key, String content)
        throws AmazonServiceException, SdkClientException {

    rejectNull(bucketName, "Bucket name must be provided");
    rejectNull(key, "Object key must be provided");
    rejectNull(content, "String content must be provided");

    byte[] contentBytes = content.getBytes(StringUtils.UTF8);

    InputStream is = new ByteArrayInputStream(contentBytes);
    ObjectMetadata metadata = new ObjectMetadata();
    metadata.setContentType("text/plain");
    metadata.setContentLength(contentBytes.length);

    return putObject(new PutObjectRequest(bucketName, key, is, metadata));
}
 
開發者ID:IBM,項目名稱:ibm-cos-sdk-java,代碼行數:18,代碼來源:AmazonS3Client.java

示例12: create

import com.amazonaws.services.s3.model.PutObjectRequest; //導入依賴的package包/類
/**
 * Constructs a new upload watcher and then immediately submits it to
 * the thread pool.
 *
 * @param manager
 *            The {@link TransferManager} that owns this upload.
 * @param transfer
 *            The transfer being processed.
 * @param threadPool
 *            The {@link ExecutorService} to which we should submit new
 *            tasks.
 * @param multipartUploadCallable
 *            The callable responsible for processing the upload
 *            asynchronously
 * @param putObjectRequest
 *            The original putObject request
 * @param progressListenerChain
 *            A chain of listeners that wish to be notified of upload
 *            progress
 */
public static UploadMonitor create(
        TransferManager manager,
        UploadImpl transfer,
        ExecutorService threadPool,
        UploadCallable multipartUploadCallable,
        PutObjectRequest putObjectRequest,
        ProgressListenerChain progressListenerChain) {

    UploadMonitor uploadMonitor = new UploadMonitor(manager, transfer,
            threadPool, multipartUploadCallable, putObjectRequest,
            progressListenerChain);
    Future<UploadResult> thisFuture = threadPool.submit(uploadMonitor);
    // Use an atomic compareAndSet to prevent a possible race between the
    // setting of the UploadMonitor's futureReference, and setting the
    // CompleteMultipartUpload's futureReference within the call() method.
    // We only want to set the futureReference to UploadMonitor's futureReference if the
    // current value is null, otherwise the futureReference that's set is
    // CompleteMultipartUpload's which is ultimately what we want.
    uploadMonitor.futureReference.compareAndSet(null, thisFuture);
    return uploadMonitor;
}
 
開發者ID:IBM,項目名稱:ibm-cos-sdk-java,代碼行數:42,代碼來源:UploadMonitor.java

示例13: putObjectUsingMetadata

import com.amazonaws.services.s3.model.PutObjectRequest; //導入依賴的package包/類
private PutObjectResult putObjectUsingMetadata(PutObjectRequest req) {
    ContentCryptoMaterial cekMaterial = createContentCryptoMaterial(req);
    // Wraps the object data with a cipher input stream
    final File fileOrig = req.getFile();
    final InputStream isOrig = req.getInputStream();
    PutObjectRequest wrappedReq = wrapWithCipher(req, cekMaterial);
    // Update the metadata
    req.setMetadata(updateMetadataWithContentCryptoMaterial(
            req.getMetadata(), req.getFile(), cekMaterial));
    // Put the encrypted object into S3
    try {
        return s3.putObject(wrappedReq);
    } finally {
        cleanupDataSource(req, fileOrig, isOrig, wrappedReq.getInputStream(), log);
    }
}
 
開發者ID:IBM,項目名稱:ibm-cos-sdk-java,代碼行數:17,代碼來源:S3CryptoModuleBase.java

示例14: shouldUploadAndDownloadObject

import com.amazonaws.services.s3.model.PutObjectRequest; //導入依賴的package包/類
/**
 * Stores a file in a previously created bucket. Downloads the file again and compares checksums
 *
 * @throws Exception if FileStreams can not be read
 */
@Test
public void shouldUploadAndDownloadObject() throws Exception {
  final File uploadFile = new File(UPLOAD_FILE_NAME);

  s3Client.createBucket(BUCKET_NAME);
  s3Client.putObject(new PutObjectRequest(BUCKET_NAME, uploadFile.getName(), uploadFile));

  final S3Object s3Object = s3Client.getObject(BUCKET_NAME, uploadFile.getName());

  final InputStream uploadFileIS = new FileInputStream(uploadFile);
  final String uploadHash = HashUtil.getDigest(uploadFileIS);
  final String downloadedHash = HashUtil.getDigest(s3Object.getObjectContent());
  uploadFileIS.close();
  s3Object.close();

  assertThat("Up- and downloaded Files should have equal Hashes", uploadHash,
      is(equalTo(downloadedHash)));
}
 
開發者ID:adobe,項目名稱:S3Mock,代碼行數:24,代碼來源:AmazonClientUploadIT.java

示例15: shouldUploadWithEncryption

import com.amazonaws.services.s3.model.PutObjectRequest; //導入依賴的package包/類
/**
 * Tests if Object can be uploaded with KMS
 */
@Test
public void shouldUploadWithEncryption() {
  final File uploadFile = new File(UPLOAD_FILE_NAME);
  final String objectKey = UPLOAD_FILE_NAME;
  s3Client.createBucket(BUCKET_NAME);
  final PutObjectRequest putObjectRequest =
      new PutObjectRequest(BUCKET_NAME, objectKey, uploadFile);
  putObjectRequest.setSSEAwsKeyManagementParams(new SSEAwsKeyManagementParams(TEST_ENC_KEYREF));

  s3Client.putObject(putObjectRequest);

  final GetObjectMetadataRequest getObjectMetadataRequest =
      new GetObjectMetadataRequest(BUCKET_NAME, objectKey);

  final ObjectMetadata objectMetadata = s3Client.getObjectMetadata(getObjectMetadataRequest);

  assertThat(objectMetadata.getContentLength(), is(uploadFile.length()));
}
 
開發者ID:adobe,項目名稱:S3Mock,代碼行數:22,代碼來源:AmazonClientUploadIT.java


注:本文中的com.amazonaws.services.s3.model.PutObjectRequest類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。