C# Класс LitS3.S3Service

Describes how to connect to a particular S3 server.
Показать файл Открыть проект Примеры использования класса

Открытые методы

Метод Описание
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.

Приватные методы

Метод Описание
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

Описание методов

AddObject() публичный Метод

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
Результат void

AddObject() публичный Метод

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
Результат void

AddObject() публичный Метод

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
Результат void

AddObject() публичный Метод

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
Результат void

AddObject() публичный Метод

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
Результат void

AddObject() публичный Метод

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
Результат void

AddObjectString() публичный Метод

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
Результат void

AddObjectString() публичный Метод

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
Результат void

CopyObject() публичный Метод

Copies an object within a bucket.
public CopyObject ( string bucketName, string sourceKey, string destKey ) : void
bucketName string
sourceKey string
destKey string
Результат void

CopyObject() публичный Метод

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
Результат void

CopyObject() публичный Метод

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
Результат void

CopyObject() публичный Метод

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
Результат void

CreateBucket() публичный Метод

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.
Результат void

CreateBucketInEurope() публичный Метод

Creates a bucket in the Amazon Europe storage location.
public CreateBucketInEurope ( string bucketName ) : void
bucketName string
Результат void

DeleteBucket() публичный Метод

Deletes the bucket with the given name.
public DeleteBucket ( string bucketName ) : void
bucketName string
Результат void

DeleteObject() публичный Метод

Deletes the object in the specified bucket with the specified key.
public DeleteObject ( string bucketName, string key ) : void
bucketName string
key string
Результат void

ForEachBucket() публичный Метод

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
Результат void

ForEachObject() публичный Метод

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
Результат void

ForEachObject() публичный Метод

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
Результат void

GetAllBuckets() публичный Метод

Lists all buckets owned by you.
public GetAllBuckets ( ) : IList
Результат IList

GetAuthorizedUrl() публичный Метод

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
Результат string

GetObject() публичный Метод

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
Результат void

GetObject() публичный Метод

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
Результат void

GetObjectStream() публичный Метод

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
Результат Stream

GetObjectStream() публичный Метод

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
Результат Stream

GetObjectString() публичный Метод

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
Результат string

GetObjectString() публичный Метод

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
Результат string

GetUrl() публичный Метод

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
Результат string

IsBucketInEurope() публичный Метод

Queries S3 to determine whether the given bucket resides in the Europe location.
public IsBucketInEurope ( string bucketName ) : bool
bucketName string
Результат bool

ListAllObjects() публичный Метод

Queries a bucket for a listing of all objects it contains. The DefaultDelimiter will be used.
public ListAllObjects ( string bucketName ) : IEnumerable
bucketName string
Результат IEnumerable

ListAllObjects() публичный Метод

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
Результат IEnumerable

ListAllObjects() публичный Метод

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
Результат IEnumerable

ListObjects() публичный Метод

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
Результат IList

ObjectExists() публичный Метод

Returns true if the given object exists in the given bucket.
public ObjectExists ( string bucketName, string key ) : bool
bucketName string
key string
Результат bool

QueryBucket() публичный Метод

Queries S3 about the existance and ownership of the given bucket name.
public QueryBucket ( string bucketName ) : BucketAccess
bucketName string
Результат BucketAccess

S3Service() публичный Метод

Creates a new S3Service with the default values.
public S3Service ( ) : System
Результат System