box-apiboxdocumentviewerboxapiv2box-view-api

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


I was wondering if it is possible to upload a file directly to be used with the Box View API without saving it on my local server. The idea is users will be able to upload a file (pdf, ppt. etc) and it will be used only with the Box Viewer and not saved in my server. Users will be uploading many large files and I am looking to avoid storing them.

I know Box requires a URL of the file location for it to generate the content, but is there a way for the file to be uploaded and handled with the View API?

If anyone knows of a solution it will be greatly appreciated! Thanks.


Solution

  • There's no way to upload directly from the user's browser, because the API does not supply CORS headers. This is for security reasons, because in order to upload directly from the client, you'd have to expose your API token (which you definitely do not want to do).

    One way to not store the files on your server would be to essentially proxy a multi-part upload request to the View API (see this gist for an example of how to do it with node.js). The other option would be to use a service such as FilePicker, which allows users to select files from their own computer or any number of other services, and it just returns a URL that you can simply pass to the View API using the URL upload.