0

I have established openstack swift connection with .net/ windows 8.1 app but i am unable to find any method to upload file or create object to openstack swift using windows 8.1 app / .net

Please help me how to upload file to openstack swift.

2 Answers2

1

I have developed a .Net Standard client for this, and implemented a WPF demo and ASP.NET Core demo. It includes authentication on OpenStack Identity, and most of actions for OpenStack switch:

NetSwiftClient

I hope it is easy to use, in that case:

var c = new SwiftClient();

if(!await AuthenticateIfNeededAsync())
{
    Log($"Could not authenticated: could not retrieve a valid token");
    return;
}

c.InitToken(Token);

var file = System.IO.File.OpenRead(NewFileSource);
string contentType = "application/octet-stream";
contentType = MimeTypeMap.GetMimeType(System.IO.Path.GetExtension(NewFileSource));

var resp = await c.ObjectPutAsync(ObjectStoreUrl, Container, NewFileName, file, contentType);
Jean
  • 4,911
  • 3
  • 29
  • 50
0

There's no easy answer to this. I'm actually seriously considering writing a swift client library for .NET to help foster more .NET development against swift.

But as it stands, you have to interact with it just as you would any other random REST API that you don't have a library for:

  1. Instantiate an HTTPWebRequest and build up the URL and headers as described in the object API documentation.
  2. The response body will usually be JSON (with one or two exceptions where you will have to manually parse or search the result). So use a JSON (de)serializer to turn the response into a table you can easily work with.

The general flow of the session is:

  1. Authenticate according to the authentication API documentation.
  2. Parse out the authentication token from the response (not JSON).
  3. Use that token in future GET/PUT requests.
  4. Remember that the token will expire after 24 hours and you will get an "access denied" error. So be sure your code knows to redo the authentication request to get a new token.

Use curl to test your API calls outside of your code to confirm what headers the requests require and what values they should have. If you don't have access to a Linux machine, you can install curl for windows, or get it with cygwin.

If you do this, please create github project and share it, if you can. You may find myself and others willing to jump in and help you!

Other alternatives:

  1. Install the swift command-line client alongside your app and call out to it. This will simplify the authentication process and the management of large objects (DLOs and SLOs), but not a lot else.
  2. Use a FUSE driver to mount a swift container as a Windows drive letter and then just talk to it like a file system. The issue here is that all of the open source swift FUSE drivers have issues. So you'll end up wanting a client that you pay for. Storage Made Easy and CloudBerry both have offerings that work well. The other option would be to install S3 API middleware (Swift3) and then use an open source S3 FUSE driver. This is known to work. But there's a lot more setup involved.
  3. Install a swift or S3-compatible gateway in front of the object store and expose containers as SMB or NFS shares. There's no free option available for this, but SoftNAS offers a great product that works well at reasonable pricing.
Adam Takvam
  • 116
  • 5
  • In Linux, you can return the authentication key (for v1.0 auth) procedurally by issuing the following command: `curl -i $ST_AUTH -H "X-Auth-User: $ST_USER" -H "X-Auth-Key: $ST_KEY" 2> /dev/null | awk '{ if($1=="X-Auth-Token:") { print $2 } }'` Set the environment variables `ST_AUTH`, `ST_USER`, and `ST_KEY` to the authentication URL, username, and password, respectively. – Adam Takvam Mar 25 '16 at 00:27