[英]How to upload files using cUrl from an ASP.NET MVC3 website?
I need to upload a file to RackSpace's Cloud Files. 我需要将文件上传到RackSpace的Cloud Files。
At their API page they have an example in cUrl, does anyone know how to implement that in C#? 在他们的API页面上,他们有一个使用cUrl编写的示例,有人知道如何在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#: 这是我需要在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 您可以使用HttpWebRequest
将PUT请求发送到服务,也可以使用更新的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);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.