简体   繁体   中英

How to use amazon S3 in c#?

I want to download files with amazon s3. I have bucketname, secret and access key.

What is region endpoint and how do I set it can I download files with this information I have

string accessKey="access key";
string secretKey="secret key";
string bucketName="my bucket name";
string directoryFile="File directory";



TransferUtility utility=new TransferUtility(client);

 //download.   --But this line error.

Error is:The request we calculated does not match the signature you provided.
Check your key and signing method.

Refer to the official sample . Check the credentials and the key name, as invalid values for those may result in the error that you are seeing.

Check your directory and file name. directory is different on desktop and server.

string accessKey="my access key";
string secretKey="my secret key";
string bucketName="my bucket name";
string directoryFile=@"C:\MyDownloadFile"; //Please check your directory access

TransferUtility fileTransferUtility =
    new TransferUtility(
        new AmazonS3Client("ACCESS-KEY-ID", "SECRET-ACCESS-KEY", Amazon.RegionEndpoint.CACentral1));

// Note the 'fileName' is the 'key' of the object in S3 (which is usually just the file name)
fileTransferUtility.Download(filePath, "my-bucket-name", fileName); // check file name as your keyName

The error infers its a Credential problem or perhaps you don't specify the KeyName - usually the keyname is just the files name:

string keyName="file.txt";
string bucketName="mybucket";
string directoryFile="C:\\MyDownloadFile";

TransferUtility utility=new TransferUtility(client);
fileTransferUtility.Download(directoryPath,bucketName,keyName); 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM