I have used the very basic code for downloading a file from Amazon S3. I have tried with two different codes.
The one which is commented
GetObjectResponse
throwing errorSystem.Xml.XmlException: There are multiple root elements. Line 2, position 2. at System.Xml.XmlTextReaderImpl.Throw(Exception e) at System.Xml.XmlTextReaderImpl.Throw(String res, String arg) at System.Xml.XmlTextReaderImpl.Throw(Int32 pos, String res) at System.Xml.XmlTextReaderImpl.ParseDocumentContent() at System.Xml.XmlTextReaderImpl.Read() at System.Xml.XmlTextReader.Read()
and etc.,
The code with the
TransferUtilityDownloadRequest
. Am not sure whether this method is correct or not. Found similar kind of example in Amazon Site so tried.
Source Code
private static void AmazonS3Access()
{
string accessKey = "my_access_key";
string secretKey = "my_secret_key";
AmazonS3Config config = new AmazonS3Config();
config.ServiceURL = "s3.amazonaws.com";
AmazonS3 client = Amazon.AWSClientFactory.CreateAmazonS3Client(
accessKey,
secretKey,
config);
GetObjectRequest request = new GetObjectRequest();
request.BucketName = "bucket";
request.Key = "myfile.extension";
try
{
TransferUtilityDownloadRequest myfile = new TransferUtilityDownloadRequest();
myfile.WithBucketName(request.BucketName);
myfile.WithKey(request.Key);
myfile.WithFilePath("D:\\S3File\\myfile.extension");
//GetObjectResponse response = client.GetObject(request);
//response.WriteResponseStreamToFile("D:\\S3File\\myfile.extension");
}
catch (Exception Ex)
{
Console.WriteLine(Ex.ToString());
}
}
How to download the object from Amazon S3. Thanks in advance.
Note:
- Am using VS 2010 with .NetFramework 3.5
- Am using AmazonSDK.dll old version
Solution:
After adding the Network Proxy Credentials in the Program, it starts working fine.