C# Class LitS3.S3Service

Describes how to connect to a particular S3 server.
Afficher le fichier Open project: ngs-doo/revenj Class Usage Examples

Méthodes publiques

Méthode 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

Méthode 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 méthode

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
Résultat void

AddObject() public méthode

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
Résultat void

AddObject() public méthode

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
Résultat void

AddObject() public méthode

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
Résultat void

AddObject() public méthode

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
Résultat void

AddObject() public méthode

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
Résultat void

AddObjectString() public méthode

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
Résultat void

AddObjectString() public méthode

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
Résultat void

CopyObject() public méthode

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

CopyObject() public méthode

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
Résultat void

CopyObject() public méthode

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
Résultat void

CopyObject() public méthode

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
Résultat void

CreateBucket() public méthode

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.
Résultat void

CreateBucketInEurope() public méthode

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

DeleteBucket() public méthode

Deletes the bucket with the given name.
public DeleteBucket ( string bucketName ) : void
bucketName string
Résultat void

DeleteObject() public méthode

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

ForEachBucket() public méthode

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
Résultat void

ForEachObject() public méthode

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
Résultat void

ForEachObject() public méthode

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
Résultat void

GetAllBuckets() public méthode

Lists all buckets owned by you.
public GetAllBuckets ( ) : IList
Résultat IList

GetAuthorizedUrl() public méthode

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
Résultat string

GetObject() public méthode

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
Résultat void

GetObject() public méthode

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
Résultat void

GetObjectStream() public méthode

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
Résultat Stream

GetObjectStream() public méthode

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
Résultat Stream

GetObjectString() public méthode

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
Résultat string

GetObjectString() public méthode

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
Résultat string

GetUrl() public méthode

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
Résultat string

IsBucketInEurope() public méthode

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

ListAllObjects() public méthode

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

ListAllObjects() public méthode

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
Résultat IEnumerable

ListAllObjects() public méthode

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
Résultat IEnumerable

ListObjects() public méthode

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
Résultat IList

ObjectExists() public méthode

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

QueryBucket() public méthode

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

S3Service() public méthode

Creates a new S3Service with the default values.
public S3Service ( ) : System
Résultat System