我正在使用RestSharp来使用Rackspace restful API here。文档向您展示了如何创建请求,但我看不出在哪里需要指定数据源(我要上传到rackspace的文件)。
PUT /<api version>/<account>/<container>/<object> HTTP/1.1
Host: storage.clouddrive.com
X-Auth-Token: eaaafd18-0fed-4b3a-81b4-663c99ec1cbb
ETag: 8a964ee2a5e88be344f36c22562a6486
Content-Length: 512000
X-Object-Meta-PIN: 1234
这就是我创建请求的方式:
string cloudPath = MainContainerName + "/" + file + "." + "wav";
string localPath = Path.Combine(System.Web.HttpContext.Current.Server.MapPath("~/Audio/Clean"), file + ".wav");
byte[] data = System.IO.File.ReadAllBytes(localPath);
RackUserAuthToken authUser = CloudLib.RackAuth.AuthenticateUser(userName, userPassword);
//Request
var containers = new RObject();
string svAddress =ConfigurationManager.AppSettings["RackSpaceStorage"];
var restClient = new RestClient();
restClient.BaseUrl = svAddress;
var request = new RestRequest(cloudPath, Method.PUT);
request.AddHeader("X-Auth-Token", authUser.AuthToken);
//request.AddHeader("ETag", localPath);
request.AddHeader("Content-Length",data.Length.ToString());
request.RequestFormat = DataFormat.Json;
var response = restClient.Execute(request);
回复是:
[{
"bytes": 0,
"content_type": "audio\/x-wav",
"hash": "d41d8cd98f00b204e9800998ecf8427e",
"last_modified": "2012-08-29T17:21:23.423150",
"name": "newTest.wav"
}]
因此文件被创建但文件中没有任何内容,因为大小为0字节。
任何帮助都非常感激。