简体   繁体   English

Dropbox:使用JavaScript将文件上传到公共文件请求

[英]Dropbox: upload file to public file request with JavaScript

I generated a public file request in Dropbox and would like to write some javascript code to programmatically upload a file which is generated on the flow (eg var myJsonString = JSON.stringify(myArray) ) to the public folder. 在Dropbox中生成了一个公共文件请求,并想编写一些JavaScript代码以编程方式将在流上生成的文件(例如var myJsonString = JSON.stringify(myArray)var myJsonString = JSON.stringify(myArray)到公共文件夹。

As an example, I created this public folder: 例如,我创建了以下公用文件夹:

https://www.dropbox.com/request/3gnn9m16eVCwxazuQIOF https://www.dropbox.com/request/3gnn9m16eVCwxazuQIOF

Since this is your Dropbox file request, you can use the standard Dropbox API to upload a file to this folder using an access token. 由于这是您的Dropbox文件请求,因此您可以使用标准的Dropbox API使用访问令牌将文件上传到此文件夹。 There's no API to anonymously upload to some one else's file request folder as a public user would via the webpage, but because this is your folder, you can also make an API proxy to do this if you wanted such an API. 没有API可以像公共用户一样通过网页匿名上传到其他人的文件请求文件夹,但是由于这是您的文件夹,因此如果需要这样的API,也可以使API代理执行此操作。

I've tested uploading to a File request folder with the API and it works fine. 我已经测试了使用API​​上传到File request文件夹的效果,效果很好。

Listing File Requests 列出文件请求

You can retrieve a list of your file requests here using the 2/file_requests/list RPC API endpoint . 您可以在此处使用2/file_requests/list RPC API端点检索文件请求2/file_requests/list

POST https://api.dropboxapi.com/2/file_requests/list

Like any Dropbox folder, you can upload to a file request via its file path specified by the destination property shown below. 与任何Dropbox文件夹一样,您可以通过如下所示的destination属性指定的文件路径将其上传到文件请求。

{
  "file_requests":[
    {
      "id":"0123456789abcdefghi",
      "url":"https://www.dropbox.com/request/0123456789abcdefghi",
      "title":"My File Request",
      "destination":"/File requests/My File Request",
      "created":"2018-06-08T15:17:45Z",
      "is_open":true,
      "file_count":0
    }
  ]
}

Uploading Files 上载档案

Once you have your specific file request folder, you can upload to it using the appropriate full path, eg /File requests/My File Request and use it in a standard RPC File Upload API call - /2/files/upload . 拥有特定的文件请求文件夹后,您可以使用适当的完整路径将其上传到该文件夹​​,例如/File requests/My File Request ,并在标准RPC File Upload API调用- /2/files/upload使用它。

POST https://content.dropboxapi.com/2/files/upload

You will need to specify a path like /File requests/My File Request/My File.png via the Dropbox-API-Arg header as specified in the API Reference: 您需要通过API参考中指定的Dropbox-API-Arg标头指定一个路径,例如/File requests/My File Request/My File.png

Web UI 网页界面

Here's a screenshot of the public request root folder in the web UI home folder. 这是Web UI主文件夹中公共请求根文件夹的屏幕快照。 The public request folder may change so it's a good idea to check the /2/file_requests/list API call specified above. 公共请求文件夹可能会更改,因此最好检查上面指定的/2/file_requests/list API调用。

在此处输入图片说明

All File Request APIs 所有文件请求API

Here's a list of the Dropbox File Request specific APIs. 以下是Dropbox文件请求特定API的列表。 As mentioned, you can use standard APIs against these folders and files as well. 如前所述,您也可以针对这些文件夹和文件使用标准API。

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

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