• <small id='0U5EZ'></small><noframes id='0U5EZ'>

  • <legend id='0U5EZ'><style id='0U5EZ'><dir id='0U5EZ'><q id='0U5EZ'></q></dir></style></legend>

        <tfoot id='0U5EZ'></tfoot>
        <i id='0U5EZ'><tr id='0U5EZ'><dt id='0U5EZ'><q id='0U5EZ'><span id='0U5EZ'><b id='0U5EZ'><form id='0U5EZ'><ins id='0U5EZ'></ins><ul id='0U5EZ'></ul><sub id='0U5EZ'></sub></form><legend id='0U5EZ'></legend><bdo id='0U5EZ'><pre id='0U5EZ'><center id='0U5EZ'></center></pre></bdo></b><th id='0U5EZ'></th></span></q></dt></tr></i><div id='0U5EZ'><tfoot id='0U5EZ'></tfoot><dl id='0U5EZ'><fieldset id='0U5EZ'></fieldset></dl></div>
        • <bdo id='0U5EZ'></bdo><ul id='0U5EZ'></ul>

        将 dataURL(base64) 保存到 PhoneGap (android) 上的文件

        Saving dataURL(base64) to file on PhoneGap (android)(将 dataURL(base64) 保存到 PhoneGap (android) 上的文件)
      1. <small id='Z1zfv'></small><noframes id='Z1zfv'>

        <tfoot id='Z1zfv'></tfoot>
          <bdo id='Z1zfv'></bdo><ul id='Z1zfv'></ul>
            <tbody id='Z1zfv'></tbody>
          <i id='Z1zfv'><tr id='Z1zfv'><dt id='Z1zfv'><q id='Z1zfv'><span id='Z1zfv'><b id='Z1zfv'><form id='Z1zfv'><ins id='Z1zfv'></ins><ul id='Z1zfv'></ul><sub id='Z1zfv'></sub></form><legend id='Z1zfv'></legend><bdo id='Z1zfv'><pre id='Z1zfv'><center id='Z1zfv'></center></pre></bdo></b><th id='Z1zfv'></th></span></q></dt></tr></i><div id='Z1zfv'><tfoot id='Z1zfv'></tfoot><dl id='Z1zfv'><fieldset id='Z1zfv'></fieldset></dl></div>

                <legend id='Z1zfv'><style id='Z1zfv'><dir id='Z1zfv'><q id='Z1zfv'></q></dir></style></legend>
                • 本文介绍了将 dataURL(base64) 保存到 PhoneGap (android) 上的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在将画布转换为 dataURL(base64) 类型,我想使用 PhoneGap 的编写器将其保存到手机文件系统,但没有成功(我得到了无法打开的损坏文件) - 这是我的一些代码:

                  I'm converting canvas to dataURL(base64) type and I wanted to save it to phone filesystem using PhoneGap's writer but without success (I get broken file which I cannot open) - here's some of my code:

                          var dataURL = document.getElementById("gen").toDataURL('image/png'); //substr() .replace('datadata:image/png;base64,', '');
                  
                           window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFS, fail);
                           function gotFS(fileSystem) {
                              fileSystem.root.getFile("screenshot.png", {create: true, exclusive: false}, gotFileEntry, fail);
                          }
                  
                          function gotFileEntry(fileEntry) {
                              fileEntry.createWriter(gotFileWriter, fail);
                          }
                  
                          function gotFileWriter(writer) {
                              console.log("open and write");
                              writer.seek(0);
                              writer.write(dataURL);
                              console.log("close and save");
                          }
                  
                          function fail(error) {
                              console.log(error.code);
                          }
                  
                          var fileTransfer = new FileTransfer();
                          fileTransfer.download("/", screenshot.png,  
                              function(entry) {
                                  alert("download complete");
                              },
                              function(error) {
                                  alert("download error source " + error.source);
                                  alert("download error target " + error.target);
                                  alert("upload error code" + error.code);
                              }
                          );
                  

                  我还尝试了 stackoverflow 的其他解决方案,它基于附加的 java 插件,但它对我不起作用.是否有纯 JS(带有额外的 js 库)解决方案?

                  I've tried also other solution from stackoverflow, which was based on addtional java plugin but it hasn't work for me. Is there pure JS(with additional js libs) solution for it?

                  推荐答案

                  您可能需要为大到足以容纳图像的文件系统请求更大的文件配额.默认值通常为 5 mb,但由于未标准化,因此在不同的浏览器中可能会有所不同.

                  You may need to request larger file quota for the file system that is big enough to hold the image. Default is typically 5 mb but may vary in the different browsers as it's not standarized.

                  如果 data-uri 的长度超过此长度(这可能是因为它是一个 PNG 文件,其中 33% 增加了 33% 作为 base64 的开销)该文件将无法正确保存.

                  If the length of the data-uri exceeds this (which is likely considering it's a PNG file with 33% added 33% overhead as base64) the file won't save properly.

                  您可以使用配额 API 请求配额:

                  You can request quota using the quota API:

                  webkitStorageInfo.requestQuota( 
                      webkitStorageInfo.PERSISTENT
                      newQuotaInBytes,
                      quotaCallback,
                      errorCallback);
                  

                  更多详情请见 这里.

                  这篇关于将 dataURL(base64) 保存到 PhoneGap (android) 上的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Fetch multiple links inside foreach loop(在 foreach 循环中获取多个链接)
                  Backbone Fetch Request is OPTIONS method(Backbone Fetch Request 是 OPTIONS 方法)
                  Fetch API leaks memory in Chrome(Fetch API 在 Chrome 中泄漏内存)
                  How can I download and save a file using the Fetch API? (Node.js)(如何使用 Fetch API 下载和保存文件?(Node.js))
                  Send blob data to node using fetch, multer, express(使用 fetch、multer、express 将 blob 数据发送到节点)
                  Sending a custom User-Agent string along with my headers (fetch)(发送自定义用户代理字符串以及我的标头(获取))
                    <bdo id='ZW8Os'></bdo><ul id='ZW8Os'></ul>
                  • <legend id='ZW8Os'><style id='ZW8Os'><dir id='ZW8Os'><q id='ZW8Os'></q></dir></style></legend>

                    1. <tfoot id='ZW8Os'></tfoot>

                          <tbody id='ZW8Os'></tbody>
                        <i id='ZW8Os'><tr id='ZW8Os'><dt id='ZW8Os'><q id='ZW8Os'><span id='ZW8Os'><b id='ZW8Os'><form id='ZW8Os'><ins id='ZW8Os'></ins><ul id='ZW8Os'></ul><sub id='ZW8Os'></sub></form><legend id='ZW8Os'></legend><bdo id='ZW8Os'><pre id='ZW8Os'><center id='ZW8Os'></center></pre></bdo></b><th id='ZW8Os'></th></span></q></dt></tr></i><div id='ZW8Os'><tfoot id='ZW8Os'></tfoot><dl id='ZW8Os'><fieldset id='ZW8Os'></fieldset></dl></div>
                          1. <small id='ZW8Os'></small><noframes id='ZW8Os'>