PageRenderTime 23ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/aws-java-sdk-s3/src/main/java/com/amazonaws/services/s3/model/PutObjectRequest.java

https://gitlab.com/github-cloud-corp/aws-sdk-java
Java | 320 lines | 101 code | 24 blank | 195 comment | 0 complexity | 9e92a109ef30811433127d7bea771d01 MD5 | raw file
  1. /*
  2. * Copyright 2014-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License").
  5. * You may not use this file except in compliance with the License.
  6. * A copy of the License is located at
  7. *
  8. * http://aws.amazon.com/apache2.0
  9. *
  10. * or in the "license" file accompanying this file. This file is distributed
  11. * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
  12. * express or implied. See the License for the specific language governing
  13. * permissions and limitations under the License.
  14. */
  15. package com.amazonaws.services.s3.model;
  16. import java.io.File;
  17. import java.io.InputStream;
  18. import java.io.Serializable;
  19. /**
  20. * <p>
  21. * Uploads a new object to the specified Amazon S3 bucket. The PutObjectRequest
  22. * optionally uploads object metadata and applies a canned access control policy
  23. * to the new object.
  24. * </p>
  25. * <p>
  26. * Amazon S3 never stores partial objects; if during this call an exception
  27. * wasn't thrown, the entire object was stored.
  28. * </p>
  29. * <p>
  30. * Depending on whether a file or input stream is being uploaded, this request
  31. * has slightly different behavior.
  32. * </p>
  33. * <p>
  34. * When uploading a file:
  35. * </p>
  36. * <ul>
  37. * <li>
  38. * The client automatically computes a checksum of the file. Amazon S3 uses
  39. * checksums to validate the data in each file.</li>
  40. * <li>
  41. * Using the file extension, Amazon S3 attempts to determine the correct content
  42. * type and content disposition to use for the object.</li>
  43. * </ul>
  44. * <p>
  45. * When uploading directly from an input stream, content length <b>must</b> be
  46. * specified before data can be uploaded to Amazon S3. If not provided, the
  47. * library will <b>have to</b> buffer the contents of the input stream in order
  48. * to calculate it. Amazon S3 explicitly requires that the content length be
  49. * sent in the request headers before any of the data is sent.</li>
  50. * <p>
  51. * Amazon S3 is a distributed system. If Amazon S3 receives multiple write
  52. * requests for the same object nearly simultaneously, all of the objects might
  53. * be stored. However, only one object will obtain the key.
  54. * </p>
  55. * <p>
  56. * Note: Amazon S3 does not provide object locking; if this is needed, make sure
  57. * to build it into the application layer.
  58. * </p>
  59. * <p>
  60. * If the caller specifies a location constraint when creating a bucket, all
  61. * objects added to the bucket are stored in the same region as the bucket. For
  62. * example, if specifying a Europe (EU) region constraint for a bucket, all of
  63. * that bucket's objects are stored in the EU region.
  64. * </p>
  65. * <p>
  66. * The specified bucket must already exist and the caller must have
  67. * {@link Permission#Write} permission to the bucket to upload an object.
  68. * </p>
  69. * <p>
  70. * If you are uploading or accessing <a
  71. * href="http://aws.amazon.com/kms/">KMS</a>-encrypted objects, you need to
  72. * specify the correct region of the bucket on your client and configure AWS
  73. * Signature Version 4 for added security. For more information on how to do
  74. * this, see
  75. * http://docs.aws.amazon.com/AmazonS3/latest/dev/UsingAWSSDK.html#specify
  76. * -signature-version
  77. * </p>
  78. *
  79. * @see PutObjectRequest#PutObjectRequest(String, String, File)
  80. * @see PutObjectRequest#PutObjectRequest(String, String, InputStream,
  81. * ObjectMetadata)
  82. */
  83. public class PutObjectRequest extends AbstractPutObjectRequest implements Serializable {
  84. /**
  85. * If enabled, the requester is charged for conducting this operation from
  86. * Requester Pays Buckets.
  87. */
  88. private boolean isRequesterPays;
  89. /**
  90. * Constructs a new
  91. * {@link PutObjectRequest} object to upload a file to the
  92. * specified bucket and key. After constructing the request,
  93. * users may optionally specify object metadata or a canned ACL as well.
  94. *
  95. * @param bucketName
  96. * The name of an existing bucket to which the new object will be
  97. * uploaded.
  98. * @param key
  99. * The key under which to store the new object.
  100. * @param file
  101. * The path of the file to upload to Amazon S3.
  102. */
  103. public PutObjectRequest(String bucketName, String key, File file) {
  104. super(bucketName, key, file);
  105. }
  106. /**
  107. * Constructs a new
  108. * {@link PutObjectRequest} object to perform a redirect for the
  109. * specified bucket and key. After constructing the request,
  110. * users may optionally specify object metadata or a canned ACL as well.
  111. * <p>
  112. * The redirect is performed using the
  113. * {@link com.amazonaws.services.s3.Headers#REDIRECT_LOCATION} header.
  114. * </p>
  115. *
  116. * @param bucketName
  117. * The name of an existing bucket to which the new object will be
  118. * uploaded.
  119. * @param key
  120. * The key under which to store the new object.
  121. * @param redirectLocation
  122. * Sets the {@link com.amazonaws.services.s3.Headers#REDIRECT_LOCATION}
  123. * header for the new object.
  124. */
  125. public PutObjectRequest(String bucketName, String key, String redirectLocation) {
  126. super(bucketName, key, redirectLocation);
  127. }
  128. /**
  129. * Constructs a new
  130. * {@link PutObjectRequest} object to upload a stream of data to
  131. * the specified bucket and key. After constructing the request,
  132. * users may optionally specify object metadata or a canned ACL as well.
  133. * <p>
  134. * Content length for the data stream <b>must</b> be
  135. * specified in the object metadata parameter; Amazon S3 requires it
  136. * be passed in before the data is uploaded. Failure to specify a content
  137. * length will cause the entire contents of the input stream to be buffered
  138. * locally in memory so that the content length can be calculated, which can
  139. * result in negative performance problems.
  140. * </p>
  141. *
  142. * @param bucketName
  143. * The name of an existing bucket to which the new object will be
  144. * uploaded.
  145. * @param key
  146. * The key under which to store the new object.
  147. * @param input
  148. * The stream of data to upload to Amazon S3.
  149. * @param metadata
  150. * The object metadata. At minimum this specifies the
  151. * content length for the stream of data being uploaded.
  152. */
  153. public PutObjectRequest(String bucketName, String key, InputStream input,
  154. ObjectMetadata metadata) {
  155. super(bucketName, key, input, metadata);
  156. }
  157. /**
  158. * Returns a clone (as deep as possible) of this request object.
  159. */
  160. @Override
  161. public PutObjectRequest clone() {
  162. PutObjectRequest request = (PutObjectRequest) super.clone();
  163. return this.copyPutObjectBaseTo(request);
  164. }
  165. @Override
  166. @SuppressWarnings("unchecked")
  167. public PutObjectRequest withBucketName(String bucketName) {
  168. return super.withBucketName(bucketName);
  169. }
  170. @Override
  171. @SuppressWarnings("unchecked")
  172. public PutObjectRequest withKey(String key) {
  173. return super.withKey(key);
  174. }
  175. @Override
  176. @SuppressWarnings("unchecked")
  177. public PutObjectRequest withStorageClass(String storageClass) {
  178. return super.withStorageClass(storageClass);
  179. }
  180. @Override
  181. @SuppressWarnings("unchecked")
  182. public PutObjectRequest withStorageClass(StorageClass storageClass) {
  183. return super.withStorageClass(storageClass);
  184. }
  185. @Override
  186. @SuppressWarnings("unchecked")
  187. public PutObjectRequest withFile(File file) {
  188. return super.withFile(file);
  189. }
  190. @Override
  191. @SuppressWarnings("unchecked")
  192. public PutObjectRequest withMetadata(ObjectMetadata metadata) {
  193. return super.withMetadata(metadata);
  194. }
  195. @Override
  196. @SuppressWarnings("unchecked")
  197. public PutObjectRequest withCannedAcl(CannedAccessControlList cannedAcl) {
  198. return super.withCannedAcl(cannedAcl);
  199. }
  200. @Override
  201. @SuppressWarnings("unchecked")
  202. public PutObjectRequest withAccessControlList(
  203. AccessControlList accessControlList) {
  204. return super.withAccessControlList(accessControlList);
  205. }
  206. @Override
  207. @SuppressWarnings("unchecked")
  208. public PutObjectRequest withInputStream(InputStream inputStream) {
  209. return super.withInputStream(inputStream);
  210. }
  211. @Override
  212. @SuppressWarnings("unchecked")
  213. public PutObjectRequest withRedirectLocation(String redirectLocation) {
  214. return super.withRedirectLocation(redirectLocation);
  215. }
  216. @Override
  217. @SuppressWarnings("unchecked")
  218. public PutObjectRequest withSSECustomerKey(SSECustomerKey sseKey) {
  219. return super.withSSECustomerKey(sseKey);
  220. }
  221. @Deprecated
  222. @Override
  223. @SuppressWarnings("unchecked")
  224. public PutObjectRequest withProgressListener(
  225. com.amazonaws.services.s3.model.ProgressListener progressListener) {
  226. return super.withProgressListener(progressListener);
  227. }
  228. @Override
  229. @SuppressWarnings("unchecked")
  230. public PutObjectRequest withSSEAwsKeyManagementParams(
  231. SSEAwsKeyManagementParams sseAwsKeyManagementParams) {
  232. return super.withSSEAwsKeyManagementParams(sseAwsKeyManagementParams);
  233. }
  234. /**
  235. * Returns true if the user has enabled Requester Pays option when
  236. * conducting this operation from Requester Pays Bucket; else false.
  237. *
  238. * <p>
  239. * If a bucket is enabled for Requester Pays, then any attempt to upload or
  240. * download an object from it without Requester Pays enabled will result in
  241. * a 403 error and the bucket owner will be charged for the request.
  242. *
  243. * <p>
  244. * Enabling Requester Pays disables the ability to have anonymous access to
  245. * this bucket
  246. *
  247. * @return true if the user has enabled Requester Pays option for
  248. * conducting this operation from Requester Pays Bucket.
  249. */
  250. public boolean isRequesterPays() {
  251. return isRequesterPays;
  252. }
  253. /**
  254. * Used for conducting this operation from a Requester Pays Bucket. If
  255. * set the requester is charged for requests from the bucket.
  256. *
  257. * <p>
  258. * If a bucket is enabled for Requester Pays, then any attempt to upload or
  259. * download an object from it without Requester Pays enabled will result in
  260. * a 403 error and the bucket owner will be charged for the request.
  261. *
  262. * <p>
  263. * Enabling Requester Pays disables the ability to have anonymous access to
  264. * this bucket.
  265. *
  266. * @param isRequesterPays
  267. * Enable Requester Pays option for the operation.
  268. */
  269. public void setRequesterPays(boolean isRequesterPays) {
  270. this.isRequesterPays = isRequesterPays;
  271. }
  272. /**
  273. * Used for conducting this operation from a Requester Pays Bucket. If
  274. * set the requester is charged for requests from the bucket. It returns this
  275. * updated PutObjectRequest object so that additional method calls can be
  276. * chained together.
  277. *
  278. * <p>
  279. * If a bucket is enabled for Requester Pays, then any attempt to upload or
  280. * download an object from it without Requester Pays enabled will result in
  281. * a 403 error and the bucket owner will be charged for the request.
  282. *
  283. * <p>
  284. * Enabling Requester Pays disables the ability to have anonymous access to
  285. * this bucket.
  286. *
  287. * @param isRequesterPays
  288. * Enable Requester Pays option for the operation.
  289. *
  290. * @return The updated PutObjectRequest object.
  291. */
  292. public PutObjectRequest withRequesterPays(boolean isRequesterPays) {
  293. setRequesterPays(isRequesterPays);
  294. return this;
  295. }
  296. }