简体   繁体   English

使用Rackspace上传文件

[英]File Upload with Rackspace

I'm using RestSharp to consume the Rackspace restful API here . 我正在使用RestSharp在这里使用Rackspace restful API。 The documentation shows you how to create the request but I don't see where do I need to specify the data source(file I want to upload to 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

This is how I'm creating the request: 这就是我创建请求的方式:

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);

The response is: 响应为:

[{
"bytes": 0,
"content_type": "audio\/x-wav",
"hash": "d41d8cd98f00b204e9800998ecf8427e",
"last_modified": "2012-08-29T17:21:23.423150",
"name": "newTest.wav"
}]

So the file gets created but there is nothing in the file, since the size is 0 bytes. 因此创建了文件,但是文件中没有任何内容,因为大小为0字节。

Any help is greatly appreciate it. 任何帮助都将不胜感激。

request.AddFile(localPath);

来自http://restsharp.org/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM