1

我在这里使用 RestSharp 来使用 Rackspace restful API 。该文档向您展示了如何创建请求,但我看不到我需要在哪里指定数据源(我想上传到机架空间的文件)。

  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 字节。

任何帮助都非常感谢。

4

1 回答 1

1
request.AddFile(localPath);

来自http://restsharp.org/

于 2012-12-12T22:50:04.500 回答