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.
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);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.