[英]Can I use Dropbox API v2 to implement cloud storage in my web app?
I was working on a web app where one of the feature was that a user logs into our system and then uploads some files. 我正在开发一个Web应用程序,其中一个功能是用户登录我们的系统,然后上传一些文件。 I was wondering if there is a way I could use my own Dropbox account to store these uploaded files in an organised and secured manner.
我想知道是否有一种方法可以使用我自己的Dropbox帐户以有组织和安全的方式存储这些上传的文件。 I would also like to retrieve these files later on so I will need to store their links in a separate database at the moment upload is done.
我还想稍后检索这些文件,因此我需要在上传完成时将其链接存储在单独的数据库中。 I am working on a node.js/JavaScript environment with Ubuntu if that matters and hosting the app on Heroku.
我正在使用Ubuntu在node.js / JavaScript环境中工作,如果这很重要并在Heroku上托管应用程序。
I think that the deprecated Datastore API had similar capability but is there a way to implement this with the API V2 ? 我认为已弃用的Datastore API具有类似的功能,但有没有办法用API V2实现这一点?
The Dropbox API does offer the ability to upload and download files, among other operations, so this should certainly be possible. Dropbox API确实提供了上传和下载文件以及其他操作的功能,因此这当然是可行的。 You can find everything you need to get started with the Dropbox API, including documentation, tutorials, and SDKs here:
您可以在此处找到开始使用Dropbox API所需的一切,包括文档,教程和SDK:
https://www.dropbox.com/developers https://www.dropbox.com/developers
It's important to note though that the Dropbox API was designed with the intention that each user would link their own Dropbox account, in order to interact with their own files. 值得注意的是,Dropbox API的设计目的是让每个用户都链接他们自己的Dropbox帐户,以便与他们自己的文件进行交互。 However, it is technically possible to connect to just one account.
但是,技术上可以连接到一个帐户。 The SDKs don't offer explicit support for it and we don't recommend doing so, for various technical and security reasons.
SDK不提供明确的支持,出于各种技术和安全原因,我们不建议这样做。 Most of these concerns are allayed for server-side apps though, where the access tokens can be kept secret.
然而,大多数这些问题都会在服务器端应用程序中得到缓解,其中访问令牌可以保密。
If you did want to go this route, instead of kicking off the authorization flow, you would manually use an existing access token for your account and app. 如果您确实想要使用此路线,而不是启动授权流程,则可以手动为您的帐户和应用使用现有的访问令牌。 (Just be careful not to revoke it, eg via https://www.dropbox.com/account/security .)
(请注意不要撤销它,例如通过https://www.dropbox.com/account/security 。)
You can quickly upload/download file using my tiny dropbox v2 api wrapper ( dropbox-v2-api ): 您可以使用我的小型Dropbox v2 api包装器( dropbox-v2-api )快速上传/下载文件:
Upload example: 上传示例:
const dropboxUploadStream = dropbox({
resource: 'files/upload',
parameters: {
path: '/dropbox/path/to/file.js'
}
}, (err, result) => {
//upload completed
});
fs.createReadStream('path/to/file.js').pipe(dropboxUploadStream);
Download example: 下载示例:
dropbox({
resource: 'files/download',
parameters: {
path: '/dropbox/image.jpg'
}
}, (err, result) => {
//download completed
})
.pipe(fs.createWriteStream('./image.jpg'));
Both combined: 两者结合:
const downloadStream = dropbox({
resource: 'files/download',
parameters: { path: '/source/file/path' }
});
const uploadStream = dropbox({
resource: 'files/upload',
parameters: { path: '/target/file/path' }
}, (err, response) => {
//upload finished
});
downloadStream.pipe(uploadStream);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.