C# Class LitS3.S3Service

Describes how to connect to a particular S3 server.
ファイルを表示 Open project: ngs-doo/revenj Class Usage Examples

Public Methods

Method Description
AddObject ( Stream inputStream, long bytes, string bucketName, string key ) : void

Adds an object to S3 by reading the specified amount of data from the given stream.

AddObject ( Stream inputStream, long bytes, string bucketName, string key, string contentType, CannedAcl acl ) : void

Adds an object to S3 by reading the specified amount of data from the given stream.

AddObject ( Stream inputStream, string bucketName, string key ) : void

Adds an object to S3 by reading all the data in the given stream. The stream must support the Length property.

AddObject ( Stream inputStream, string bucketName, string key, string contentType, CannedAcl acl ) : void

Adds an object to S3 by reading all the data in the given stream. The stream must support the Length property.

AddObject ( string bucketName, string key, long bytes, Action action ) : void

Adds an object to S3 by acquiring the upload stream then allowing the given function to handle writing data into it.

AddObject ( string bucketName, string key, long bytes, string contentType, CannedAcl acl, Action action ) : void

Adds an object to S3 by acquiring the upload stream then allowing the given function to handle writing data into it.

AddObjectString ( string contents, string bucketName, string key ) : void

Uploads the contents of a string to S3. This method is only appropriate for small objects and testing. The UTF-8 encoding will be used.

AddObjectString ( string contents, string bucketName, string key, string contentType, CannedAcl acl ) : void

Uploads the contents of a string to S3. This method is only appropriate for small objects and testing. The UTF-8 encoding will be used.

CopyObject ( string bucketName, string sourceKey, string destKey ) : void

Copies an object within a bucket.

CopyObject ( string bucketName, string sourceKey, string destKey, CannedAcl acl ) : void

Copies an object within a bucket and assigns the given canned ACL.

CopyObject ( string sourceBucketName, string sourceKey, string destBucketName, string destKey ) : void

Copies an object from one bucket to another.

CopyObject ( string sourceBucketName, string sourceKey, string destBucketName, string destKey, CannedAcl acl ) : void

Copies an object from one bucket to another with the given canned ACL.

CreateBucket ( string bucketName ) : void

Creates a bucket in the default storage location automatically determined by Amazon.

CreateBucketInEurope ( string bucketName ) : void

Creates a bucket in the Amazon Europe storage location.

DeleteBucket ( string bucketName ) : void

Deletes the bucket with the given name.

DeleteObject ( string bucketName, string key ) : void

Deletes the object in the specified bucket with the specified key.

ForEachBucket ( Action action ) : void

Performs the given action on each of your buckets without loading the list of buckets completely into memory.

ForEachObject ( string bucketName, Action action ) : void

Queries a bucket for a listing of objects it contains and performs the given action on each object. The DefaultDelimiter will be used.

ForEachObject ( string bucketName, string prefix, Action action ) : void

Queries a bucket for a listing of objects it contains and performs the given action on each object. Only objects with keys beginning with the given prefix will be returned. The DefaultDelimiter will be used.

GetAllBuckets ( ) : IList

Lists all buckets owned by you.

GetAuthorizedUrl ( string bucketName, string key, System.DateTime expires ) : string

Creates a pre-authorized URI valid for performing a GET on the given S3 object in the given bucket. This is useful for constructing a URL to hand over to a 3rd party (such as a web browser). The Uri will automatically expire after the time given. This method itself does not communicate with S3 and will return immediately.

You might expect this method to return a System.Uri instead of a string. It turns out there is a tricky issue with constructing Uri objects from these pre-authenticated url strings: The Uri.ToString() method will convert a properly-encoded "+" character back into a raw "+", which is interpreted by Amazon S3 as a space (standard URI conventions). So the signature will be misread if you were to take the Uri.ToString() and feed it to a browser. So instead, we'll give you a properly escaped URL string which will always work in a browser. If you want to, say, use it in a WebRequest instead, it turns out that WebRequest will leave it escaped properly and everything will work.

GetObject ( string bucketName, string key, Stream outputStream ) : void

Gets an existing object in S3 and copies its data to the given Stream.

GetObject ( string bucketName, string key, Stream outputStream, long &contentLength, string &contentType ) : void

Gets an existing object in S3 and copies its data to the given Stream.

GetObjectStream ( string bucketName, string key ) : Stream

Gets a data stream for an existing object in S3. It is your responsibility to close the Stream when you are finished.

GetObjectStream ( string bucketName, string key, long &contentLength, string &contentType ) : Stream

Gets a data stream for an existing object in S3. It is your responsibility to close the Stream when you are finished.

GetObjectString ( string bucketName, string key ) : string

Downloads an existing object in S3 and loads the entire contents into a string. This is only appropriate for very small objects and for testing.

GetObjectString ( string bucketName, string key, string &contentType ) : string

Downloads an existing object in S3 and loads the entire contents into a string. This is only appropriate for very small objects and for testing.

GetUrl ( string bucketName, string key ) : string

This constructs a Uri suitable for accessing the given object in the given bucket. It is not authorized, so it will only work for objects with anonymous read access. This method itself does not communicate with S3 and will return immediately.

IsBucketInEurope ( string bucketName ) : bool

Queries S3 to determine whether the given bucket resides in the Europe location.

ListAllObjects ( string bucketName ) : IEnumerable

Queries a bucket for a listing of all objects it contains. The DefaultDelimiter will be used.

ListAllObjects ( string bucketName, string prefix ) : IEnumerable

Queries a bucket for a listing of objects it contains. Only objects with keys beginning with the given prefix will be returned. The DefaultDelimiter will be used.

ListAllObjects ( string bucketName, string prefix, string delimiter ) : IEnumerable

Queries a bucket for a listing of objects it contains. Only objects with keys beginning with the given prefix will be returned.

ListObjects ( string bucketName, string prefix ) : IList

Queries a bucket for a listing of objects it contains. Only objects with keys beginning with the given prefix will be returned. The DefaultDelimiter will be used. If you expect a large number of objects to be returned, consider using ListAllObjects().

ObjectExists ( string bucketName, string key ) : bool

Returns true if the given object exists in the given bucket.

QueryBucket ( string bucketName ) : BucketAccess

Queries S3 about the existance and ownership of the given bucket name.

S3Service ( ) : System

Creates a new S3Service with the default values.

Private Methods

Method Description
AuthorizeRequest ( S3Request request, HttpWebRequest webRequest, string bucketName ) : void
CopyStream ( Stream source, Stream dest, long length, Action progressCallback ) : void
CreateProgressCallback ( string bucketName, string key, long length, EventHandler handler ) : Action

Method Details

AddObject() public method

Adds an object to S3 by reading the specified amount of data from the given stream.
public AddObject ( Stream inputStream, long bytes, string bucketName, string key ) : void
inputStream Stream
bytes long
bucketName string
key string
return void

AddObject() public method

Adds an object to S3 by reading the specified amount of data from the given stream.
public AddObject ( Stream inputStream, long bytes, string bucketName, string key, string contentType, CannedAcl acl ) : void
inputStream Stream
bytes long
bucketName string
key string
contentType string
acl CannedAcl
return void

AddObject() public method

Adds an object to S3 by reading all the data in the given stream. The stream must support the Length property.
public AddObject ( Stream inputStream, string bucketName, string key ) : void
inputStream Stream
bucketName string
key string
return void

AddObject() public method

Adds an object to S3 by reading all the data in the given stream. The stream must support the Length property.
public AddObject ( Stream inputStream, string bucketName, string key, string contentType, CannedAcl acl ) : void
inputStream Stream
bucketName string
key string
contentType string
acl CannedAcl
return void

AddObject() public method

Adds an object to S3 by acquiring the upload stream then allowing the given function to handle writing data into it.
public AddObject ( string bucketName, string key, long bytes, Action action ) : void
bucketName string
key string
bytes long
action Action
return void

AddObject() public method

Adds an object to S3 by acquiring the upload stream then allowing the given function to handle writing data into it.
public AddObject ( string bucketName, string key, long bytes, string contentType, CannedAcl acl, Action action ) : void
bucketName string
key string
bytes long
contentType string
acl CannedAcl
action Action
return void

AddObjectString() public method

Uploads the contents of a string to S3. This method is only appropriate for small objects and testing. The UTF-8 encoding will be used.
public AddObjectString ( string contents, string bucketName, string key ) : void
contents string
bucketName string
key string
return void

AddObjectString() public method

Uploads the contents of a string to S3. This method is only appropriate for small objects and testing. The UTF-8 encoding will be used.
public AddObjectString ( string contents, string bucketName, string key, string contentType, CannedAcl acl ) : void
contents string
bucketName string
key string
contentType string
acl CannedAcl
return void

CopyObject() public method

Copies an object within a bucket.
public CopyObject ( string bucketName, string sourceKey, string destKey ) : void
bucketName string
sourceKey string
destKey string
return void

CopyObject() public method

Copies an object within a bucket and assigns the given canned ACL.
public CopyObject ( string bucketName, string sourceKey, string destKey, CannedAcl acl ) : void
bucketName string
sourceKey string
destKey string
acl CannedAcl
return void

CopyObject() public method

Copies an object from one bucket to another.
public CopyObject ( string sourceBucketName, string sourceKey, string destBucketName, string destKey ) : void
sourceBucketName string
sourceKey string
destBucketName string
destKey string
return void

CopyObject() public method

Copies an object from one bucket to another with the given canned ACL.
public CopyObject ( string sourceBucketName, string sourceKey, string destBucketName, string destKey, CannedAcl acl ) : void
sourceBucketName string
sourceKey string
destBucketName string
destKey string
acl CannedAcl
return void

CreateBucket() public method

Creates a bucket in the default storage location automatically determined by Amazon.
public CreateBucket ( string bucketName ) : void
bucketName string The name of the bucket, which will be checked against /// the BucketNameChecking.Strict requirements.
return void

CreateBucketInEurope() public method

Creates a bucket in the Amazon Europe storage location.
public CreateBucketInEurope ( string bucketName ) : void
bucketName string
return void

DeleteBucket() public method

Deletes the bucket with the given name.
public DeleteBucket ( string bucketName ) : void
bucketName string
return void

DeleteObject() public method

Deletes the object in the specified bucket with the specified key.
public DeleteObject ( string bucketName, string key ) : void
bucketName string
key string
return void

ForEachBucket() public method

Performs the given action on each of your buckets without loading the list of buckets completely into memory.
public ForEachBucket ( Action action ) : void
action Action
return void

ForEachObject() public method

Queries a bucket for a listing of objects it contains and performs the given action on each object. The DefaultDelimiter will be used.
public ForEachObject ( string bucketName, Action action ) : void
bucketName string
action Action
return void

ForEachObject() public method

Queries a bucket for a listing of objects it contains and performs the given action on each object. Only objects with keys beginning with the given prefix will be returned. The DefaultDelimiter will be used.
public ForEachObject ( string bucketName, string prefix, Action action ) : void
bucketName string
prefix string
action Action
return void

GetAllBuckets() public method

Lists all buckets owned by you.
public GetAllBuckets ( ) : IList
return IList

GetAuthorizedUrl() public method

Creates a pre-authorized URI valid for performing a GET on the given S3 object in the given bucket. This is useful for constructing a URL to hand over to a 3rd party (such as a web browser). The Uri will automatically expire after the time given. This method itself does not communicate with S3 and will return immediately.
You might expect this method to return a System.Uri instead of a string. It turns out there is a tricky issue with constructing Uri objects from these pre-authenticated url strings: The Uri.ToString() method will convert a properly-encoded "+" character back into a raw "+", which is interpreted by Amazon S3 as a space (standard URI conventions). So the signature will be misread if you were to take the Uri.ToString() and feed it to a browser. So instead, we'll give you a properly escaped URL string which will always work in a browser. If you want to, say, use it in a WebRequest instead, it turns out that WebRequest will leave it escaped properly and everything will work.
public GetAuthorizedUrl ( string bucketName, string key, System.DateTime expires ) : string
bucketName string
key string
expires System.DateTime
return string

GetObject() public method

Gets an existing object in S3 and copies its data to the given Stream.
public GetObject ( string bucketName, string key, Stream outputStream ) : void
bucketName string
key string
outputStream Stream
return void

GetObject() public method

Gets an existing object in S3 and copies its data to the given Stream.
public GetObject ( string bucketName, string key, Stream outputStream, long &contentLength, string &contentType ) : void
bucketName string
key string
outputStream Stream
contentLength long
contentType string
return void

GetObjectStream() public method

Gets a data stream for an existing object in S3. It is your responsibility to close the Stream when you are finished.
public GetObjectStream ( string bucketName, string key ) : Stream
bucketName string
key string
return Stream

GetObjectStream() public method

Gets a data stream for an existing object in S3. It is your responsibility to close the Stream when you are finished.
public GetObjectStream ( string bucketName, string key, long &contentLength, string &contentType ) : Stream
bucketName string
key string
contentLength long
contentType string
return Stream

GetObjectString() public method

Downloads an existing object in S3 and loads the entire contents into a string. This is only appropriate for very small objects and for testing.
public GetObjectString ( string bucketName, string key ) : string
bucketName string
key string
return string

GetObjectString() public method

Downloads an existing object in S3 and loads the entire contents into a string. This is only appropriate for very small objects and for testing.
public GetObjectString ( string bucketName, string key, string &contentType ) : string
bucketName string
key string
contentType string
return string

GetUrl() public method

This constructs a Uri suitable for accessing the given object in the given bucket. It is not authorized, so it will only work for objects with anonymous read access. This method itself does not communicate with S3 and will return immediately.
public GetUrl ( string bucketName, string key ) : string
bucketName string
key string
return string

IsBucketInEurope() public method

Queries S3 to determine whether the given bucket resides in the Europe location.
public IsBucketInEurope ( string bucketName ) : bool
bucketName string
return bool

ListAllObjects() public method

Queries a bucket for a listing of all objects it contains. The DefaultDelimiter will be used.
public ListAllObjects ( string bucketName ) : IEnumerable
bucketName string
return IEnumerable

ListAllObjects() public method

Queries a bucket for a listing of objects it contains. Only objects with keys beginning with the given prefix will be returned. The DefaultDelimiter will be used.
public ListAllObjects ( string bucketName, string prefix ) : IEnumerable
bucketName string
prefix string
return IEnumerable

ListAllObjects() public method

Queries a bucket for a listing of objects it contains. Only objects with keys beginning with the given prefix will be returned.
public ListAllObjects ( string bucketName, string prefix, string delimiter ) : IEnumerable
bucketName string
prefix string
delimiter string
return IEnumerable

ListObjects() public method

Queries a bucket for a listing of objects it contains. Only objects with keys beginning with the given prefix will be returned. The DefaultDelimiter will be used. If you expect a large number of objects to be returned, consider using ListAllObjects().
public ListObjects ( string bucketName, string prefix ) : IList
bucketName string
prefix string
return IList

ObjectExists() public method

Returns true if the given object exists in the given bucket.
public ObjectExists ( string bucketName, string key ) : bool
bucketName string
key string
return bool

QueryBucket() public method

Queries S3 about the existance and ownership of the given bucket name.
public QueryBucket ( string bucketName ) : BucketAccess
bucketName string
return BucketAccess

S3Service() public method

Creates a new S3Service with the default values.
public S3Service ( ) : System
return System