S3StorageProvider extends StorageProviderBase { public String addHiddenContent(String spaceId, String contentId, String contentMimeType, InputStream content) { log.debug("addHiddenContent(" + spaceId + ", " + contentId + ", " + contentMimeType + ")"); String bucketName = getBucketName(spaceId); if (contentMimeType == null || contentMimeType.equals("")) { contentMimeType = DEFAULT_MIMETYPE; } ObjectMetadata objMetadata = new ObjectMetadata(); objMetadata.setContentType(contentMimeType); PutObjectRequest putRequest = new PutObjectRequest(bucketName, contentId, content, objMetadata); putRequest.setStorageClass(DEFAULT_STORAGE_CLASS); putRequest.setCannedAcl(CannedAccessControlList.Private); try { PutObjectResult putResult = s3Client.putObject(putRequest); return putResult.getETag(); } catch (AmazonClientException e) { String err = "Could not add content " + contentId + " with type " + contentMimeType + " to S3 bucket " + bucketName + " due to error: " + e.getMessage(); throw new StorageException(err, e, NO_RETRY); } } S3StorageProvider(String accessKey, String secretKey);  S3StorageProvider(String accessKey,
                             String secretKey,
                             Map<String, String> options);  S3StorageProvider(AmazonS3 s3Client,
                             String accessKey,
                             Map<String, String> options); @Override StorageProviderType getStorageProviderType(); Iterator<String> getSpaces(); Iterator<String> getSpaceContents(String spaceId,
                                             String prefix); List<String> getSpaceContentsChunked(String spaceId,
                                                String prefix,
                                                long maxResults,
                                                String marker); void createSpace(String spaceId); String createHiddenSpace(String spaceId, int expirationInDays); void setSpaceLifecycle(String bucketName,
                                  BucketLifecycleConfiguration config); void removeSpace(String spaceId); String addHiddenContent(String spaceId,
                                   String contentId,
                                   String contentMimeType,
                                   InputStream content); String addContent(String spaceId,
                             String contentId,
                             String contentMimeType,
                             Map<String, String> userProperties,
                             long contentSize,
                             String contentChecksum,
                             InputStream content); @Override String copyContent(String sourceSpaceId,
                              String sourceContentId,
                              String destSpaceId,
                              String destContentId); RetrievedContent getContent(String spaceId, String contentId); RetrievedContent getContent(String spaceId, String contentId, String range); void deleteContent(String spaceId, String contentId); void setContentProperties(String spaceId,
                                     String contentId,
                                     Map<String, String> contentProperties); Map<String, String> getContentProperties(String spaceId,
                                                    String contentId); @Override Map<String, String> getSpaceProperties(String spaceId); String getBucketName(String spaceId); static final String HIDDEN_SPACE_PREFIX; }
@Test public void testAddHiddenContent() throws Exception { setupS3Client(); S3StorageProvider provider = getProvider(); String hiddenSpace = "my-hidden-space"; String etag = "etag"; String bucketName = getBucketName(hiddenSpace); Bucket bucket = createMock("ListedBucket", Bucket.class); String data = "contents"; InputStream content = IOUtil.writeStringToStream(data); String mimeType = "mime"; Capture<PutObjectRequest> requestCapture = newCapture(); PutObjectResult result = createMock("AddHiddenContentResult", PutObjectResult.class); expect(result.getETag()).andReturn(etag); expect(s3Client.putObject(capture(requestCapture))).andReturn(result); expect(bucket.getName()).andReturn(bucketName); expect(s3Client.listBuckets()).andReturn(Arrays.asList(bucket)); replay(s3Client, bucket, result); String resultETag = provider.addHiddenContent(hiddenSpace, contentId, mimeType, content); PutObjectRequest request = requestCapture.getValue(); assertEquals("etag must be returned", etag, resultETag); assertEquals("unexpected bucket name", bucketName, request.getBucketName()); assertEquals("unexpected mimetype", mimeType, request.getMetadata().getContentType()); assertEquals("unexpected access control list", CannedAccessControlList.Private, request.getCannedAcl()); verify(result, bucket); }