我正在使用Dropbox API将文件上传到Dropbox云。我有访问令牌,我需要执行以下curl命令:
curl -H "Authorization: Bearer NBNBNSBJHDKHDKJJGGD" https://api-content.dropbox.com/1/files_put/auto/ -T "C:\Tm\dd.jpg"
有人可以告诉我如何在C#中执行上述操作
感谢您的帮助
答案 0 :(得分:0)
感谢您的支持。这解决了。我觉得这对某些人来说绝对有用。
string filePath="C:\\Tim\\sundar.jpg";
RestClient client = new RestClient("https://api-content.dropbox.com/1/");
IRestRequest request = new RestRequest("files_put/auto/{path}", Method.PUT);
FileInfo fileInfo = new FileInfo(filePath);
long fileLength = fileInfo.Length;
request.AddHeader("Authorization", "Bearer FTXXXXXXXXXXXXXXXXXXXisqFXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
request.AddHeader("Content-Length", fileLength.ToString());
request.AddUrlSegment("path", string.Format("Public/{0}", fileInfo.Name));
byte[] data = File.ReadAllBytes(filePath);
var body = new Parameter
{
Name = "file",
Value = data,
Type = ParameterType.RequestBody,
};
request.Parameters.Add(body);
IRestResponse response = client.Execute(request);