如何使用JS SDK将文件上传到Dropbox? [英] How to upload a file to Dropbox using JS SDK?

查看:122
本文介绍了如何使用JS SDK将文件上传到Dropbox?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  1. 我不确定是将文件读取为数组缓冲区还是dataURI或二进制流.哪个更好?

  1. I am not sure whether to read the file as as Array Buffer or as a dataURI or as a binary stream. Which would be better?

此外,这些方法是否会占用大量内存,并使应用程序/设备运行缓慢,尤其是在上传150mb左右的大文件时?

Also, won't these methods be memory intensive and make the app/device slow, especially when uploading big files like 150mb or so?

还有另一件事是,该文件是否将像原来一样是可打开的"? 示例:如果我使用其中一种方法读取了.zip文件,然后又下载了该文件,它仍会以ZIP格式打开吗?

And yet another thing is whether the file will be "openable" as it was originally? Example: If I read a .zip file using one of the methods and then download the file later, will it still open as ZIP?

由于这种类比,我感到部分困惑:我们可以轻松地查看JPG或PNG文件,也可以使用它们的dataURI(base-64)在浏览器中显示它们...但是当我们保存base-64字符串作为JPG或PNG文件,无法看到该图像.因此,我无法理解如何读取文件内容以便能够将其上传到保管箱(请记住,文件也可以达到150MB左右),并且仍然保留文件的原始格式.

I am partly confused because of this analogy: We can easily view a JPG or PNG file and we can also display them in a browser using their dataURI (base-64)... but when we save that base-64 string as a JPG or PNG file, the image cannot be seen. Therefore, I cannot understand how should I read the contents of the file to be able to upload it on dropbox (keeping in mind that a file can be around 150MB too) and still retain how the file originally was.

假设我要上传.mp3或.zip文件.然后,如何使用Javascript Dropbox SDK将其上传到用户的Dropbox帐户?

Let's say I want to upload an .mp3 or a .zip file. Then how should I upload this to a user's dropbox account using the Javascript Dropbox SDK?

请清除这种混乱并帮助我!

Kindly clear this confusion and help me out!

谢谢!

推荐答案

使用 Dropbox API时v2 JavaScript SDK :

  1. 上传文件时,应在contents参数中提供数据,例如,在 filesUpload方法.目前应该支持stringBuffer.
  1. When uploading files, you should supply the data in the contents parameter, e.g., on the filesUpload method. That should currently support either string or Buffer.

一个示例在这里的节点中.

  1. 对于像这样的大文件,您应该改用上传会话,这样可以上传较小的文件:
  1. For large files like this, you should instead use upload sessions, which allows you to upload files in smaller pieces:
    • filesUploadSessionStart
    • filesUploadSessionAppendV2
    • filesUploadSessionFinish

一个示例在这里使用这些.您可以选择制作每块的大小.

There's an example of using these here. You can choose how big to make each piece.

  1. 您上传到Dropbox的文件将完全包含您在上传调用中提供的数据.因此,如果您上传一个zip文件,然后稍后再次下载,它仍将采用相同的格式;对于zip文件,这意味着您可以将其解压缩.

请注意,上传文件数据时,请勿对文件数据应用任何额外的编码.例如,当在浏览器中显示图像时,您可以对数据进行base64编码以使其在数据URI中可用,但在上传文件进行存储时则不应这样做.

Note that you should not apply any extra encoding to the file data when uploading it. For example, when displaying an image in a browser, you may base64 encode the data to make it usable in a data URI, but you should not do so when uploading the file for storage.

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

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