12 ratings
  • 1
  • 2
  • 3
  • 4
  • 5
5 star 10
4 star 2
3 star 0
2 star 0
1 star 0
Compatible with
  • Android
  • iOS
  • Windows

Amazon S3 1.5.225.0

DataNuage S.A.S.

Use Amazon S3 to store and retrieve any amount of data at any time, from anywhere.

DataNuage.Aws.S3 is a client library that uses Amazon S3 to store and retrieve any amount of data at any time, from anywhere.

support@datanuage.com

Your access key and your private key need to be passed as parameters of the constructor of the S3 class. Once you have an instance of S3, your can create buckets (similar to folders) and objects as in the example below.

YOU SHOULD ONLY UPLOAD DUMMY DATA WHILE USING THE TRIAL VERSION OF THE SOFTWARE AS EVERY TRIAL USER SHARES THE SAME AWS ACCOUNT. Any user of the trial version of the SOFTWARE will be able to view, copy, delete any data you might upload during the trial.

using DataNuage.Aws;
...

public override void ViewDidLoad()
{
    base.ViewDidLoad();

    View.Frame = UIScreen.MainScreen.Bounds;
    View.BackgroundColor = UIColor.White;
    View.AutoresizingMask = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight;

    button = UIButton.FromType(UIButtonType.RoundedRect);

    button.Frame = new RectangleF(
        View.Frame.Width / 2 - buttonWidth / 2,
        View.Frame.Height / 2 - buttonHeight / 2,
        buttonWidth,
        buttonHeight);

    button.SetTitle("Click me", UIControlState.Normal);

    button.TouchUpInside += async (object sender, EventArgs e) =>
        {
            button.SetTitle("In progress", UIControlState.Normal);

            var random = new Random();

            var s3 = new S3("<Your AWS S3 Access Key Id> - ignored by Trial version",
                "<Your AWS S3 Secret Access Key> - ignored by Trial version");

            var bucket = "my-globally-unique-bucket-name" + random.Next();

            try
            {
                await s3.CreateBucketAsync(bucket);
                button.SetTitle(String.Format("Bucket {0} created", bucket), UIControlState.Normal);

                await s3.PutObjectAsync(bucket, "myobject", "Hello World");
                button.SetTitle(String.Format("Object myobject created"), UIControlState.Normal);

                var s = await s3.GetObjectAsStringAsync(bucket, "myobject");
                button.SetTitle(String.Format("{0} read", s), UIControlState.Normal);

                await s3.DeleteObjectAsync(bucket, "myobject");
                button.SetTitle(String.Format("Object myobject deleted"), UIControlState.Normal);

                var dummyData = new byte[1000000];
                await s3.PutObjectAsync(bucket, "big", dummyData, progress: l => button.SetTitle(string.Format("Upload {0}%", (100 * l) / dummyData.Length), UIControlState.Normal));

                await s3.DeleteObjectAsync(bucket, "big");

                await s3.DeleteBucketAsync(bucket);
                button.SetTitle(String.Format("Empty bucket {0} deleted", bucket), UIControlState.Normal);

                button.SetTitle("Success", UIControlState.Normal);
            }
            catch (Exception ex)
            {
                new UIAlertView("Error", ex.Message, null, "ok", null).Show();
                button.SetTitle("Click me", UIControlState.Normal);
            }
        };

    button.AutoresizingMask = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleTopMargin |
        UIViewAutoresizing.FlexibleBottomMargin;

    View.AddSubview(button);
}

How do I make an S3 object accessible from a web page ?

If you want your object to be accessible by a browser, C# code not using the DataNuage.Aws.S3 library or any HTTP GET request, you need to make it "PublicRead". You may also have to set its content-type so that it is recognised for what it is (not just a collection of bytes).

await PutObjectAsync("bucket name", "object name", data, Acl.PublicRead, "image/jpeg")

If your file is not a jpeg image, look here for appropriate content types http://en.wikipedia.org/wiki/Internet_media_type

The URL of the public object is always of the form http(s)://s3.amazonaws.com/my-globally-unique-bucket-name/my-object-name S3 also treat the bucket name as a subdomain so http(s)://my-globally-unique-bucket-name.s3.amazonaws.com/my-object-name is valid as well.

How do I create folders ?

S3 does not have the concept of folders. It only deals with buckets and objects. A bucket must have a name that is unique across all S3 users worldwide and it can only contain objects (no bucket in buckets).

Having said that, it is fairly easy to simulate folder structures by adding slashes ('/') to the object name:

var s3 = new S3("<Your AWS S3 Access Key Id> - ignored by Trial version",
        "<Your AWS S3 Secret Access Key> - ignored by Trial version");

await s3.PutObjectAsync("my-globally-unique-bucket-name", "myfolder/myotherfolder/obj.txt", "Hello World", Acl.PublicRead);

var wc = new WebClient();
var s = wc.DownloadString("http://s3.amazonaws.com/my-globally-unique-bucket-name/myfolder/myotherfolder/obj.txt");

Assert.IsTrue(s == "Hello World");

await s3.DeleteObjectAsync("my-globally-unique-bucket-name", "myfolder/myotherfolder/obj.txt");

I do not feel comfortable storing my private key on the device, is there an alternative ?

Yes, you can generate pre-signed urls that can be used without the private key (you only need the private key to generate them). How you distribute the urls to the device is up to you.

The way you would typically use pre-signed urls is as follow:

// START OF SERVER CODE
var s3 = new S3("...", "...");

// Create the bucket (do it only the first time)
await s3.CreateBucketAsync("my-presigned-test-bucket");

await s3.PutObjectAsync("my-presigned-test-bucket", "myobject", "Hello");

var read = s3.GetPreSignedGetUrl("my-presigned-test-bucket", "myobject", DateTime.UtcNow.AddDays(1));
var write = s3.GetPreSignedPutUrl("my-presigned-test-bucket", "myobject", DateTime.UtcNow.AddDays(1));
var delete = s3.GetPreSignedDeleteUrl("my-presigned-test-bucket", "myobject", DateTime.UtcNow.AddDays(1));

//END OF SERVER CODE


// Send read/write/delete urls (strings) to device by whichever means you see fit


//START OF DEVICE CODE

var ps3 = new PreSignedS3(); // Set timeout and/or proxy here if necessary

var hello = await ps3.GetObjectAsStringAsync(read); // Hello
await ps3.PutObjectAsync(write, "Goodbye");// Set object content to 'Goodbye'
await ps3.DeleteObjectAsync(delete);// Delete object

//END OF DEVICE CODE

Release Notes

Various improvements.

Write a Review

6 reviews

Truong Thien Nguyen rates this with
  • 1
  • 2
  • 3
  • 4
  • 5

I'm coming from Unity development background. I'm really happy that Xamarin is developing a market place that is beneficial for developer to help developer with reasonable prices which is very successful for Unity and its developer.

This component is one of my first purchase on this store. The trial version worked like a charm so I paid and get the premium version.

Unfortunately, it doesn't work out of the box when I hook my S3 account in, the developer is kind enough to reply my enquiry within few hours of requesting support and via TeamViewer remote desktop, he has pinpointed the issue (due to my S3 region is Sydney and need to be specified when setup).

Tremendous level of support. Highly recommended plugin. Dead simple to setup. Role model for other developers in Xamarin market place.

Posted on: May 26, 2015 / Version: 1.5.216.0
Colin Brown rates this with
  • 1
  • 2
  • 3
  • 4
  • 5

Great component, does what it says on the tin. Great support too, got back to me with a detailed solution to my problem within hours.

Posted on: December 16, 2014 / Version: 1.4.182.0
Roy Cockram rates this with
  • 1
  • 2
  • 3
  • 4
  • 5

Can't fault this component, simple to use and developer support is excellent. I have been using it since version 1.1 (mid Oct), just updated to 1.4 to make use of the the progress notifications for uploads and again works great.

Posted on: December 14, 2014 / Version: 1.4.182.0
Matthew Waring rates this with
  • 1
  • 2
  • 3
  • 4
  • 5

Adding to the existing sentiments about Developer Support in the other reviews. We require S3 Upload cancellation as part of our requirements for the use of this component and the developer has gone out of their way to provide first class support for all questions we have asked of them. An excellent experience all round.

Posted on: November 13, 2014 / Version: 1.2.160.0
Bernie Habermeier rates this with
  • 1
  • 2
  • 3
  • 4
  • 5

A key aspect for our team when relying on a 3rd party component is the ability of support to help out with queries and important additions where required. Let me just say that the developer for this component has been outstanding in all areas, quickly adding progress updates to S3 uploads when asked for help. Highly recommended.

Posted on: October 28, 2014 / Version: 1.2.160.0
patrick dengler rates this with
  • 1
  • 2
  • 3
  • 4
  • 5

At first I had problems with the lack of exposed APi's and the inability to set permissions. It seems that the gentelman working on this agressively res[ponded to me with a new build to make sure i kept going. So the coverage is getting there, though I think it is still not yet all in the store, and well done on being proactive and reactive.

Posted on: September 29, 2014 / Version: 1.0.90.0