Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Writing to a file on Amazon s3 bucket using c#

I have a text file on my amazon s3 bucket and I want to write some text at the end of that file. Something like following : xxxxxx|xxxxxx|xxxxx|xxxx. I want to do this with c#. I did tried using streamwriter but it did not worked.

using(StreamWriter writer = new StreamWriter(Server.MapPath(url), true))
{
  writer.WriteLine("xxxxxxxx|xxxxxxxxxxx|xxxxxxx|xxxxxxxxxx");
}

My initial guess is that there must be some kind of authentication requirements. Can anyone help me out or direct to appropriate resources.

like image 518
slonkar Avatar asked Nov 02 '12 18:11

slonkar


People also ask

Can you write to a file in S3?

You can use the Object. put() method available in the S3 object. It allows two ways to write into the S3.

How do I write to Amazon S3 bucket?

Sign in to the AWS Management Console and open the Amazon S3 console at https://console.aws.amazon.com/s3/ . In the Buckets list, choose the name of the bucket that you want to upload your folders or files to. Choose Upload.


1 Answers

Amazon S3 doesn't support appending to objects. You would have to read the entire object from S3, then put it back again with the new data.

The AWS SDK for .NET (See http://aws.amazon.com/sdkfornet ) provides tools that will make authenticated S3 operations easier to manage in C#, including treating S3 buckets like a local filesystem (See http://docs.amazonwebservices.com/sdkfornet/latest/apidocs/html/N_Amazon_S3_IO.htm)

like image 126
Jim Flanagan Avatar answered Sep 21 '22 12:09

Jim Flanagan