用于文件上传的Dropbox Core API [英] Dropbox Core API for file uploads

查看:366
本文介绍了用于文件上传的Dropbox Core API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我运行一个由其用户访问的服务,以生成PDF文档,然后通过电子邮件发送给他们。我正在探索一个替代的传递途径 - 直接在他们指定的Dropbox文件夹中弹出准备好的文档。

I run a service that is visited by its users to generate PDF documents that are then delivered to them by email. I am in the process of exploring an alternative delivery route - popping the prepared document directly in a Dropbox folder that they designate.

经过一番研究,我发现了 Dropbox API ,然后使用他们的explorer此处。检查它们生成的cURL以执行文件上传我发现它可以很容易地用一个PHP的地方。创建新应用程序后,我写了一个小的PHP脚本

After a spot of research I discovered the Dropbox API and then played with their "explorer" here. Examining the cURL they generate to perform a file upload I found that it could quite easily be done with a spot of PHP. After creating a new app I then wrote out a little PHP script

$headers = array('Authorization: Bearer ul...',
                  'Content-Type: application/octet-stream',
                  'Dropbox-API-Arg: {"path":"/test.txt","mode":"add"}');
$data = 'Betty bought a bit of butter';

$ch = curl_init('https://content.dropboxapi.com/2-beta-2/files/upload/');
curl_setopt($ch,CURLOPT_HTTPHEADER,$headers);
curl_setopt($ch,CURLOPT_POST,true);
curl_setopt($ch,CURLOPT_POSTFIELDS,$data);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
$response = curl_exec($ch);
curl_close($ch);
echo $response;

运行这个脚本一切正常工作 - 我的Dropbox中有问题的文件一秒。

On running this script everything worked just perfectly - the file in question turned up in my Dropbox in a fraction of a second.

一切都很好。但是,我在Dropbox API的头几分钟,这里有很多我不明白的地方。

All very nice. However, I am into my first few minutes with the Dropbox API and there is much that I do not understand here



  • 在我的例子中,我的服务的用户必须为我提供一个有效的应用程序令牌,我可以使用上面的 Authorization:Bearer ... 位。我假设这个标记限制我只能在他们的 app 文件夹范围内工作?他们自然会不愿意交出一个令牌,让我做他想要的Dropbox。 *不用说,这将取决于他们将应用权限类型配置为应用文件夹

  • Is the code I wrote above by blindly mimicking their explorer sample code the right way to do file uploads?
  • In my case it is the users of my service who will have to provide me with a valid App token I can use above in the Authorization:Bearer... bit. I assume that this token constrains me to only working within the confines of their app folder? They would, naturally, be unwilling to hand over a token that lets me do what I will with their Dropbox. *Needless to say - this would be conditional on their configuring their "App" permission type to App Folder.

我非常感谢任何反馈,我可以从我的方法,特别是其中的缺陷,从那些谁知道Dropbox API比我更好。

I'd much appreciate any feedback I can get on my approach - particularly the flaws in it - from those who know the Dropbox API better than I.

推荐答案

Dropbox API Explorer使用新的Dropbox API v2,它刚刚开始测试。您可以在这里找到官方文档,包括curl示例:

The Dropbox API Explorer uses the new Dropbox API v2, which just came out of beta. You can find the official documentation, including a curl example, here:

https://www.dropbox.com/developers/documentation/http#documentation-files-upload

只要你使用它的文档(例如,你应该使用/ 2 / now而不是/ 2-beta-2 /),应该很好。

As long as you're using it as documented there, (e.g., you should use /2/ now instead of /2-beta-2/), it should be fine.

关于权限,有几个选择(虽然API v2目前只支持应用程序文件夹和完整的Dropbox),并且开发人员在应用程序注册时选择该权限:

Regarding permissions, there are a few to pick from (though API v2 currently only supports app folder and full Dropbox), and the permission is chosen by the developer when the app is registered:

https://www.dropbox.com/developers / reference / devguide#app-permissions

应用程式连结至应用程式后,只要使用者的Dropbox帐户遭到存取权限, 。

The access token your app gets for a user's Dropbox account once they link to the app is constrained to the app's permission.

在你的情况下,听起来像是应用程序文件夹权限就足够了。

In your case, it sounds like the app folder permission would be sufficient.

这篇关于用于文件上传的Dropbox Core API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆