Can Dropbox Saver accept data from createObjectURL()?

こ雲淡風輕ζ 提交于 2019-12-04 16:48:08

As in James Foster's comment above, Dropbox now accepts data URIs. Consequently, if one has the data in the form of a data URI, one can call Dropbox.save(dataURI,filename,options) as documented here.

But there is a slight problem: To create a data URI the usual way (with FileReader) requires an asynchronous call to readAsDataURL. But Dropbox.save() can only be called in response to a user interaction (such as a click). So in a click handler, if you must first create the data URI asynchronously, then by the time you get to the callback, the Dropbox.save() function can no longer be called.

In my case, it was possible to create the data URI without the FileReader API, since I was only storing HTML data. One can simply write "data:text/html,"+encodeURIComponent(myHTMLData) to create the data URI, as documented here. For non-text data that solution will not work, and you'd have to try something more complicated, perhaps like what's documented here.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!