简体   繁体   English

Dropbox选择器:使用javascript获取文件内容

[英]Dropbox chooser : get content of the file in javascript

I use dropbox chooser in an HTML5 application and the API don't give you the file itself , it give the direct link to download the file. 我在HTML5应用程序中使用了保管箱选择器,而API并没有给您文件本身,而是提供了直接链接来下载文件。 Something like : " https://dl.dropboxusercontent.com/1/view/ydld54fs5sford8/myFolder/myFile.csv ". 类似于:“ https://dl.dropboxusercontent.com/1/view/ydld54fs5sford8/myFolder/myFile.csv ”。

How can I manage to download this file in javascript to get a file object and then read the content of this file ? 我如何设法使用javascript下载此文件以获得文件对象,然后读取该文件的内容?

You can just use a standard AJAX call. 您可以只使用标准的AJAX调用。 For example, using jQuery: 例如,使用jQuery:

$.get('https://dl.dropboxusercontent.com/1/...', function (data) {
    console.log(data); // <-- this will log the contents of the file
});

EDIT 编辑

Make sure you're using a direct link (one that looks like https://dl.dropboxusercontent.com/1/... ), not a preview link (which points to an HTML page on www.dropbox.com ). 确保您使用的是直接链接(看起来像https://dl.dropboxusercontent.com/1/... ),而不是预览链接(指向www.dropbox.com上的HTML页面)。

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

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