Box View API : 可以直接上传文件吗?

Box View API : Is it possible to upload a file directly?

我想知道是否可以直接上传文件以用于 Box View API 而无需将其保存在我的本地服务器上。这个想法是用户将能够上传文件(pdf、ppt 等),并且它只能与 Box Viewer 一起使用,而不会保存在我的服务器中。用户将上传许多大文件,我希望避免存储它们。

我知道 Box 需要 URL 文件位置才能生成内容,但是有没有办法使用视图 API 上传和处理文件?

如果有人知道解决方案,将不胜感激!谢谢

无法直接从用户的浏览器上传,因为 API 不提供 CORS headers。这是出于安全原因,因为为了直接从客户端上传,您必须公开您的 API 令牌(您绝对不想这样做)。

一种不将文件存储在服务器上的方法实际上是将 multi-part 上传请求代理到视图 API(参见此 gist for an example of how to do it with node.js). The other option would be to use a service such as FilePicker,它允许用户 select 文件来自他们自己的计算机或任意数量的其他服务,它只是 returns 一个 URL,您可以使用 URL 简单地传递给视图 API上传。

多部分 API 只是发送大文件时的一个选项。这是尝试发送小文件的响应:

{"data":
{"code":"file_size_too_small",
"message":"File size 23 less than minimum allowed for this API: 20000000",
"request_id":"aab58e965e91c8aa7283b2faddec5ab3"},
"status":400,"config":{"method":"POST",
"transformRequest":[null],
"transformResponse":[null],
"jsonpCallbackParam":"callback",
"url":"https://upload.box.com/api/2.0/files/upload_sessions",
"headers":{"Authorization":"Bearer xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"Content-Type":"multipart/form-data",
"Accept":"application/json, text/plain, */*"},
"data":{"folder_id":"111111111111",
"file_size":23,
"file_name":"TestUploadFile.txt"}},
"statusText":"Bad Request",
"xhrStatus":"complete"}