-
Notifications
You must be signed in to change notification settings - Fork 4
Home
This wiki should help you get started with Storj/Tardigrade and the uplink.NET-library.
Create a new .Net-project (.Net, UWP and Xamarin.Android will work currently) and add the "uplink.NET"-Nuget to the project.
To use the library you need an account on a Storj/Tardigrade-satellite or a local storj-sim-environment. See tardigrade.io for further info. If you have access to a satellite, create a new project and API key.
Then you'll need to init uplink.NET like this. First, init a Scope using your API-Key, your satellite-address, your encryption secret and a temp-path to use:
Scope.SetTempDirectory(System.IO.Path.GetTempPath());
_scope = new Scope("YOUR_API_KEY_HERE", "YOUR_SATELLITE_URL_WITH:PORT_HERE", "YOUR_PESONAL_ENCRYPTION_KEY");
If you're on Android, set the temp-directory like this:
Scope.SetTempDirectory(CacheDir.AbsolutePath);
Then you'll be able to use the BucketService and the ObjectService like this:
var bucketService = new BucketService(_scope);
BucketListOptions listOptions = new BucketListOptions();
var buckets = await bucketService.ListBucketsAsync(listOptions);
To add a new bucket, use the CreateBucket-Method. You may alter the BucketConfig but the default values are good to go:
var bucketInfo = await bucketService.CreateBucketAsync("mybucket", new BucketConfig());
Listing, uploading and downloading of objects (i.e. binary data) works through the ObjectService. The following code would open a bucket "testbucket" and list all objects within the bucket:
var bucketService = new BucketService(_scope);
var bucket = await bucketService.OpenBucketAsync("testbucket");
var objectService = new ObjectService();
var listOptions = new ListOptions();
listOptions.Direction = ListDirection.STORJ_AFTER;
var objects = await objectService.ListObjectsAsync(bucket, listOptions);
foreach (var obj in objects.Items)
{
//work with the objects
}
To download the object "test.jpg" from "testbucket" using the open bucket do the following:
var downloadOperation = objectService.DownloadObjectAsync(bucket,"test.jpg",false);
downloadOperation.DownloadOperationProgressChanged += //add event handler
await downloadOperation.StartDownloadAsync();
The same would be for an upload.