List of usage examples for com.amazonaws.services.s3.model PutObjectRequest setTagging
public void setTagging(ObjectTagging tagging)
From source file:com.universal.storage.UniversalS3Storage.java
License:Open Source License
/** * This method uploads a file with a length lesser than PART_SIZE (5Mb). * // w ww. j a v a 2 s .c o m * @param file to be stored within the storage. * @param path is the path for this new file within the root. * @throws UniversalIOException when a specific IO error occurs. */ private void uploadTinyFile(File file, String path) throws UniversalIOException { try { ObjectMetadata objectMetadata = new ObjectMetadata(); if (this.settings.getEncryption()) { objectMetadata.setSSEAlgorithm(ObjectMetadata.AES_256_SERVER_SIDE_ENCRYPTION); } List<Tag> tags = new ArrayList<Tag>(); for (String key : this.settings.getTags().keySet()) { tags.add(new Tag(key, this.settings.getTags().get(key))); } PutObjectRequest request = new PutObjectRequest( this.settings.getRoot() + ("".equals(path) ? "" : ("/" + path)), file.getName(), file); request.setMetadata(objectMetadata); request.setTagging(new ObjectTagging(tags)); request.setStorageClass(getStorageClass()); this.triggerOnStoreFileListeners(); PutObjectResult result = this.s3client.putObject(request); this.triggerOnFileStoredListeners(new UniversalStorageData(file.getName(), PREFIX_S3_URL + (this.settings.getRoot() + ("".equals(path) ? "" : ("/" + path))) + "/" + file.getName(), result.getVersionId(), this.settings.getRoot() + ("".equals(path) ? "" : ("/" + path)))); } catch (Exception e) { UniversalIOException error = new UniversalIOException(e.getMessage()); this.triggerOnErrorListeners(error); throw error; } }