/* * Copyright 2018-2023 Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"). * You may not use this file except in compliance with the License. * A copy of the License is located at * * http://aws.amazon.com/apache2.0 * * or in the "license" file accompanying this file. This file is distributed * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either * express or implied. See the License for the specific language governing * permissions and limitations under the License. */ package com.amazonaws.services.s3.model; import com.amazonaws.AmazonWebServiceRequest; import com.amazonaws.http.HttpMethodName; import java.io.File; import java.io.InputStream; import java.io.Serializable; import java.net.URL; /** * Request class to upload a object to S3 using presigned urls. Upload content can be provided through a file or input stream. * * The behavior is similar to using {@link PutObjectRequest}. Depending on whether a file or input stream is being uploaded, * this request has slightly different behavior. *
** When uploading a file: *
** Amazon S3 is a distributed system. If Amazon S3 receives multiple write * requests for the same object nearly simultaneously, all of the objects might * be stored. However, only one object will obtain the key. *
* * If custom headers are used in generating the url, you can set them through {@link #putCustomRequestHeader(String, String)} * method. If any signed headers or parameters are missing from the request, a Signature mismatch error will be thrown from S3. * Ensure you set all the custom headers/parameters that are used for creating the presigned url. */ public class PresignedUrlUploadRequest extends AmazonWebServiceRequest implements S3DataSource, Serializable { private static final long serialVersionUID = 1L; private URL presignedUrl; private HttpMethodName httpMethodName = HttpMethodName.PUT; /** * The file containing the data to be uploaded to Amazon S3. You must either * specify a file or an InputStream containing the data to be uploaded to * Amazon S3. */ private File file; /** * The InputStream containing the data to be uploaded to Amazon S3. You must * either specify a file or an InputStream containing the data to be * uploaded to Amazon S3. */ private transient InputStream inputStream; /** * Optional metadata instructing Amazon S3 how to handle the uploaded data * (e.g. custom user metadata, hooks for specifying content type, etc.). If * you are uploading from an InputStream, you* If uploading from an input stream, * always specify metadata with the content size set. Otherwise the * contents of the input stream have to be buffered in memory before * being sent to Amazon S3. This can cause very negative performance * impacts. *
* * @return The optional metadata instructing Amazon S3 how to handle the * uploaded data (e.g. custom user metadata, hooks for specifying * content type, etc.). */ public ObjectMetadata getMetadata() { return metadata; } /** * Sets the optional metadata instructing Amazon S3 how to handle the * uploaded data (e.g. custom user metadata, hooks for specifying content * type, etc.). ** If uploading from an input stream, * always specify metadata with the content size set. Otherwise the * contents of the input stream have to be buffered in memory before * being sent to Amazon S3. This can cause very negative performance * impacts. *
* * @param metadata * The optional metadata instructing Amazon S3 how to handle the * uploaded data (e.g. custom user metadata, hooks for specifying * content type, etc.). */ public void setMetadata(ObjectMetadata metadata) { this.metadata = metadata; } /** * Sets the optional metadata instructing Amazon S3 how to handle the * uploaded data (e.g. custom user metadata, hooks for specifying content * type, etc.). ** If uploading from an input stream, * always specify metadata with the content size set. Otherwise the * contents of the input stream have to be buffered in memory before * being sent to Amazon S3. This can cause very negative performance * impacts. *
* * @param metadata * The optional metadata instructing Amazon S3 how to handle the * uploaded data (e.g. custom user metadata, hooks for specifying * content type, etc.). * * @return This object for method chaining */ public PresignedUrlUploadRequest withMetadata(ObjectMetadata metadata) { setMetadata(metadata); return this; } }