简体   繁体   English

在XmlHttpRequest readyState 4内调用Chrome ChooseEntry

[英]Calling chrome chooseEntry inside XmlHttpRequest readyState 4

I'm trying to save an image in fileSystem from my blob response but the file dialog is not showing, this is my script: 我正在尝试从Blob响应中将图像保存到fileSystem中,但是未显示文件对话框,这是我的脚本:

var xhr2 = new XMLHttpRequest();
xhr2.open("GET", "http://website.org?url=http://www.google.com");
xhr2.responseType = "blob";
xhr2.onreadystatechange = function() {
    if (xhr2.readyState == 4) {
        console.log(xhr2.response); //Blob {type: "text/xml", size: 17830, slice: function}
        $('img')[0].src=window.URL.createObjectURL(xhr2.response); //response image is showing fine

        console.log($('#mydiv').attr('id')+'.jpg'); //suggestedName is 'web:file.html.jpg'
        chrome.fileSystem.chooseEntry({ type:'saveFile',suggestedName:$('#mydiv').text()+'.jpg',accepts:[{ extensions:['jpg'] }] },function(fileEntry){
        //chooseEntry is not creating file dialog
            console.log(fileEntry); //undefined
        });
    }
};
xhr2.send(null);

Manifest.json 的manifest.json

"permissions": [
    "http://www.website.org",
    "syncFileSystem",
    {"fileSystem": ["write", "directory"]}
],

Ok, I solved it. 好的,我解决了。 Apparently the suggestedName value cannot have the character ':' 显然,suggestedName值不能包含字符“:”

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

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