使用 Devdefined OAuth 库将文件上传到 Dropbox
我正在尝试将文件上传到 Dropbox REST Web 服务,同时使用 Devdefine 的 OAuth 库。
这是我正在使用的方法:
public static void UploadFile(string filenameIn, string directoryIn, byte[] dataIn)
{
DropBox.session.Request().Put().ForUrl("https://api-content.dropbox.com/1/files_put/" + directoryIn + filenameIn)
.WithQueryParameters(new { param = dataIn });
}
该方法似乎没有执行任何操作,也没有抛出任何异常。输出也没有错误。我尝试使用断点来确认它也在调用代码。
I am trying to upload a file to the Dropbox REST web service while at the same time using Devdefined's OAuth library.
This is the method I'm using:
public static void UploadFile(string filenameIn, string directoryIn, byte[] dataIn)
{
DropBox.session.Request().Put().ForUrl("https://api-content.dropbox.com/1/files_put/" + directoryIn + filenameIn)
.WithQueryParameters(new { param = dataIn });
}
The method doesn't appear to do anything, nor throw any exceptions. There's no errors in the output either. I've tried using breakpoints to confirm it's calling the code as well.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您没有收到错误的原因是因为请求没有被执行 - 要执行请求,您需要获取响应 - 有多种方法可以做到这一点,但通常最简单的就是使用以下命令取回文本ReadBody() 方法。
上传文件的内容不能作为查询参数来完成 - 根据 dropbox REST API,放置请求的整个正文应该是文件的内容。
本质上,要使这一切正常工作,您需要:
结果将是一个包含 JSON 的字符串,应如下所示:
我已在 github 上的 DevDefined.OAuth-examples 项目中添加了一个示例,该示例演示了如何使用 DropBox 执行 GET 和 PUT 请求:
https://github.com/bittercoder/DevDefined.OAuth-Examples/blob/master/src/ExampleDropBoxUpload/Program.cs
这是放置请求特别需要的代码:
希望应该把事情弄清楚一点,不幸的是,没有文档,仅通过查看源代码来弄清楚这些事情有点棘手:)
The reason you are not receiving an error is because the request is not being executed - to execute the request you need to fetch the response - there is a number of ways to do this, but often the simplest is just to fetch the text back using the method ReadBody().
Uploading the contents of a file can not be done as a query parameter - as per the dropbox REST API, the entire body of the put request should be the file's contents.
Essentially for this all to work you will need to:
The result will be a string containing JSON that should look something like this:
I've added an example to the DevDefined.OAuth-examples project on github that demonstrates how to do GET and PUT requests with DropBox:
https://github.com/bittercoder/DevDefined.OAuth-Examples/blob/master/src/ExampleDropBoxUpload/Program.cs
And here's the code specifically required for a put request:
Hopefully that should clear things up a bit, unfortunately without documentation it's a little tricky to figure these things out by just looking at the source code :)