问题描述
是否可以将服务器上的pdf文件保存到chrome打包的应用程序中?
Is there any way to save pdf files from server to chrome packaged app?
在我的chrome打包应用中,我有类似的东西,
In my chrome packaged app, i have some thing like this,
下载
当用户单击此超级链接时,我应该能够将该pdf文件下载到我的chrome打包的应用程序文件系统中.
when user clicks on this hyper link, i should able download that pdf file into my chrome packaged app file system.
推荐答案
下载PDF文件没有什么特别的地方.使用XMLHttpRequest
下载文件,然后使用文件API将其写入沙盒文件或使用chrome.fileSystem.chooseEntry
获得其FileEntry
的外部文件.
There's nothing special about downloading PDF files. Use XMLHttpRequest
to download a file, and then use the file APIs to either write it to a sandboxed file, or to an external file whose FileEntry
you get with chrome.fileSystem.chooseEntry
.
下载后,如果先使用FileReader.readAsDataURL
将PDF转换为数据URL,则可以在Web视图中显示PDF或提供链接以在外部浏览器中打开它. (您不能将下载的文件作为file://
URL引用.)
Once downloaded, you can display the PDF in a webview or provide a link to open it in an external browser if you first convert it to a data URL with FileReader.readAsDataURL
. (You can't reference the downloaded file as file://
URL.)
(Chrome应用程序不应被称为打包"应用程序,因为后者是指现在已经过时的旧版应用程序技术.)
(Chrome Apps should not be referred to as "packaged" apps, as the latter term refers to a now-obsolete legacy app technology.)
更新:要将下载的Blob保存到文件中,
Update: To save the downloaded blob to a file:
// Save a blob in a FileEntry
// (e.g., from a call to chrome.fileSystem.chooseEntry)
function saveToEntry(blob, fileEntry) {
fileEntry.createWriter(
function(writer) {
writer.onerror = errorHandler; // you supply this
writer.truncate(0);
writer.onwriteend = function () {
writer.write(blob);
writer.onwriteend = function () {
// blob has been written
};
};
},
errorHandler // you supply this
);
}
这篇关于将外部pdf文件下载到chrome打包的应用程序的文件系统中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!