dgogoasa
// Get an amazon S3 client
try
{
AmazonS3Config config = new AmazonS3Config();
config.RegionEndpoint ="Your region"
m_s3Client = new AmazonS3Client("Your access key",
"Your secret key",
config);
m_connected = true;
}
catch (Exception ex)
{
// Handle exception
m_connected = false;
}
/// Use it to get the file
if (m_connected)
try
{
GetObjectRequest request=
new GetObjectRequest
{
BucketName = bucketName,
Key = Key // Key is of the form "folder/folder/filename"
// or if the file is directly in bucket just "filename"
};
using (GetObjectResponse response = m_s3Client.GetObject(request))
using (Stream responseStream = response.ResponseStream)
using (StreamReader reader = new StreamReader(responseStream))
{
string contentType = response.Headers["Content-Type"];
string responseBody = reader.ReadToEnd();
// Now you process the response body.
if (File.Exists(SelectedToDownload.FileName))
File.Delete(SelectedToDownload.FileName);
File.WriteAllText(SelectedToDownload.FileName, responseBody);
string readText = File.ReadAllText(SelectedToDownload.FileName);
}
catch (AmazonS3Exception e)
{
// Handle Exceptions
}