C# |
public class GetPreSignedUrlRequest : S3Request
All Members | Constructors | Methods | Properties | ||
Icon | Member | Description |
---|---|---|
GetPreSignedUrlRequest()()()() | Initializes a new instance of the GetPreSignedUrlRequest class | |
AddHeader(String, String) |
Adds the header to the collection of headers for the request.
(Inherited from S3Request.) | |
AddHeaders(NameValueCollection) |
Adds all of the specified key/value pairs into the request headers collection.
(Inherited from S3Request.) | |
BucketName |
The name of the bucket to create a pre-signed url to, or containing the object.
| |
ContentType |
A standard MIME type describing the format of the object data.
| |
Equals(Object) | (Inherited from Object.) | |
Expires |
The expiry date and time for the pre-signed url.
| |
GetHashCode()()()() | Serves as a hash function for a particular type. (Inherited from Object.) | |
GetType()()()() | Gets the type of the current instance. (Inherited from Object.) | |
InputStream |
Input stream for the request; content for the request will be read from the stream.
(Inherited from S3Request.) | |
IsSetExpires()()()() |
Checks if Expires property is set.
| |
Key |
The key to the object for which a pre-signed url should be created.
| |
Protocol |
The requested protocol (http/https) for the pre-signed url.
| |
ReadWriteTimeout |
Overrides the default HttpWebRequest ReadWriteTimeout value.
(Inherited from S3Request.) | |
ResponseHeaderOverrides |
A set of response headers that should be returned with the pre-signed url creation response.
| |
ServerSideEncryptionMethod |
Specifies the encryption used on the server to store the content.
| |
Timeout |
Overrides the default HttpWebRequest timeout value.
(Inherited from S3Request.) | |
ToString()()()() | (Inherited from S3Request.) | |
Verb |
The verb for the pre-signed url.
| |
VersionId |
Version id for the object that the pre-signed url will reference. If not set,
the url will reference the latest version of the object.
| |
WithBucketName(String) | Obsolete.
Sets the name of the bucket for which a pre-signed url is requested, or containing the object
with key Key.
| |
WithContentType(String) | Obsolete.
A standard MIME type describing the format of the object data.
| |
WithExpires(DateTime) | Obsolete.
Sets the expiry date and time for the pre-signed url.
| |
WithInputStream(Stream) | Obsolete.
Sets an input stream for the request; content for the request will be read from the stream.
(Inherited from S3Request.) | |
WithKey(String) | Obsolete.
Sets the key to the object for which a pre-signed url should be created.
| |
WithProtocol(Protocol) | Obsolete.
Sets the requested protocol (http/https) for the pre-signed url.
| |
WithReadWriteTimeout(Int32) | Obsolete.
Overrides the default HttpWebRequest ReadWriteTimeout value.
(Inherited from S3Request.) | |
WithResponseHeaderOverrides(ResponseHeaderOverrides) | Obsolete.
A set of response headers that should be returned with the pre-signed url creation response.
| |
WithServerSideEncryptionMethod(ServerSideEncryptionMethod) | Obsolete.
Specifies the encryption used on the server to store the content.
| |
WithTimeout(Int32) | Obsolete.
Overrides the default HttpWebRequest timeout value.
(Inherited from S3Request.) | |
WithVerb(HttpVerb) | Obsolete.
Sets the verb for the pre-signed url.
| |
WithVersionId(String) | Obsolete.
Sets the version id for the object that the pre-signed url will reference. If not set,
the url will reference the latest version of the object.
|
Required Parameters: BucketName, Expires
Optional Parameters: Key, VersionId, Verb: default is GET
The following examples show how to create various different pre-signed URLs.
The code sample shows a GetContents function. This will be referred to in subsequent samples to test out the generated URL.
public static string GetContents(string path) { HttpWebRequest request = HttpWebRequest.Create(path) as HttpWebRequest; HttpWebResponse response = request.GetResponse() as HttpWebResponse; using (Stream stream = response.GetResponseStream()) using (StreamReader reader = new StreamReader(stream)) { return reader.ReadToEnd(); } }
The first example creates a URL that will allow a third party to retrieve an object from S3 for a period of 5 minutes.
// Create a client AmazonS3Client client = new AmazonS3Client(); // Create a CopyObject request GetPreSignedUrlRequest request = new GetPreSignedUrlRequest { BucketName = "SampleBucket", Key = "Item1", Expires = DateTime.Now.AddMinutes(5) }; // Get path for request string path = client.GetPreSignedURL(request); // Test by getting contents string contents = GetContents(path);
The following example creates a URL that will allow a third party to retrieve an object from S3 for a period of 5 minutes, and it also sets the headers to specific content, caching and encoding values.
// Create a client AmazonS3Client client = new AmazonS3Client(); // Create a CopyObject request GetPreSignedUrlRequest request = new GetPreSignedUrlRequest { BucketName = "SampleBucket", Key = "Item1", Expires = DateTime.Now.AddMinutes(5) }; request.ResponseHeaderOverrides.ContentType = "text/xml+zip"; request.ResponseHeaderOverrides.ContentDisposition = "attachment; filename=dispName.pdf"; request.ResponseHeaderOverrides.CacheControl = "No-cache"; request.ResponseHeaderOverrides.ContentLanguage = "mi, en"; request.ResponseHeaderOverrides.Expires = "Thu, 01 Dec 1994 16:00:00 GMT"; request.ResponseHeaderOverrides.ContentEncoding = "x-gzip"; // Get path for request string path = client.GetPreSignedURL(request); // Test by getting contents string contents = GetContents(path);
This example creates a URL that will allow a third party to list
all objects in a specific bucket. This URL will also expire in 5 minutes.
The URL response will be the XML response for a ListBucket request.
// Create a client AmazonS3Client client = new AmazonS3Client(); // Create a CopyObject request GetPreSignedUrlRequest request = new GetPreSignedUrlRequest { BucketName = "SampleBucket", Expires = DateTime.Now.AddMinutes(5) }; // Get path for request string path = client.GetPreSignedURL(request); // Retrieve objects string allObjects = GetContents(path);
This example creates a URL that will allow a third party to list
all of the owner's buckets. This URL will also expire in 5 minutes.
The URL response will be the XML response for a ListBuckets request.
// Create a client AmazonS3Client client = new AmazonS3Client(); // Create a CopyObject request GetPreSignedUrlRequest request = new GetPreSignedUrlRequest { Expires = DateTime.Now.AddMinutes(5) }; // Get path for request string path = client.GetPreSignedURL(request); // Retrieve buckets string allBuckets = GetContents(path);
This final example creates a URL that allows a third party to put an object, then uses it to upload sample content. The URL is set to expire in 10 days.
// Create a client AmazonS3Client client = new AmazonS3Client(); // Create a CopyObject request GetPreSignedUrlRequest request = new GetPreSignedUrlRequest { BucketName = "SampleBucket", Key = "Item1", Verb = HttpVerb.PUT, Expires = DateTime.Now.AddDays(10) }; // Get path for request string path = client.GetPreSignedURL(request); // Prepare data byte[] data = UTF8Encoding.UTF8.GetBytes("Sample text."); // Configure request HttpWebRequest httpRequest = WebRequest.Create(path) as HttpWebRequest; httpRequest.Method = "PUT"; httpRequest.ContentLength = data.Length; // Write data to stream Stream requestStream = httpRequest.GetRequestStream(); requestStream.Write(data, 0, data.Length); requestStream.Close(); // Issue request HttpWebResponse response = httpRequest.GetResponse() as HttpWebResponse;