0

I need to upload a file to RackSpace's Cloud Files.

At their API page they have an example in cUrl, does anyone know how to implement that in C#?

Any north would be much appreciated since my search is not being helpful, all I found even here were codes that looked a lot like a regular upload.

Here's the example I need working in C#:

Upload File to Container
curl -X PUT -T screenies/hello.jpg -D - \
-H "ETag: 805120e285a7ed28f74024422fe3594" \
-H "Content-Type: image/jpeg" \
-H "X-Auth-Token: fc81aaa6-98a1-9ab0-94ba-aba9a89aa9ae" \
-H "X-Object-Meta-Screenie: Hello World" \

https://storage.clouddrive.com/v1/CF_xer7_343/
images/hello.jpg

HTTP/1.1 201 Created
Date: Thu, 09 July 2009 17:03:36 GMT
Server: Apache
Content-Length: 0
ETag: 805120e285a7ed28f74024422fe3594
Content-Type: text/plain

Just to be clear, I don't want anyone to do my work for me, I just need some tutorial or north as I said.

Thanks.

1 Answer 1

1

You could use either HttpWebRequest to send the PUT request to the service or the newer HttpClient api

See a sample below.

var client = new HttpClient();
client.DefaultRequestHeaders.Add("X-Auth_User", "your_username");
client.DefaultRequestHeaders.Add("X-Auth-Key", "your_api_key");

 client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("image/pjpeg"));

var bytes = File.ReadAllBytes(imagePath);
var ms = new MemoryStream(bytes);

 client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("image/pjpeg"));
 var content = new StreamContent(ms);


 var response = client.PutAsync("YOUR_RACKSPACE_URI", content);
Sign up to request clarification or add additional context in comments.

6 Comments

So I would send the file in a regular way, only using PUT as request method?
I'm not sure how rackspace cloud files works but i guess they'll be some sort of auth going on before you can upload.
They do, and I know I'll have to use NetworkCredentials for that. But I just want to confirm that it will be a regular upload, right? I was just searching for HttpClient and saw it for WCF, does it work for non-WCF?
Ok, thanks for your answer, I'll try that right now and will accept the answer if that works. Thanks for your time.
@eestein i've updated my answer with a sample which may help.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.