Chrome extension : Download/export content created “on the fly”

前端 未结 3 914
攒了一身酷
攒了一身酷 2021-01-02 16:07

I need to let the user to download a file created on the fly from some data contained in the extension, but I don\'t want to do this server-side.

As a real-world ex

相关标签:
3条回答
  • 2021-01-02 16:43

    I don't think this is possible because of safety reasons

    0 讨论(0)
  • 2021-01-02 16:50

    In the Chromium-extensions Google Group I have found this working example: (I have modified it to work from the pop-up)

    BuiltBlob = new BlobBuilder(""); 
    BuiltBlob.append("Hello, world"); 
    BlobToSave = BuiltBlob.getBlob(); 
    chrome.tabs.create({'url': createObjectURL(BlobToSave), 'selected': false});
    

    But the filename is not set, ending with something like cf8a56bf-d724-4b97-b10f-e252961135bd

    On the The W3C docs ( http://dev.w3.org/2009/dap/file-system/file-writer.html ) I've found this not working example:

    var bb = new BlobBuilder(); 
    bb.append("Lorem ipsum"); 
    var fileSaver = window.saveAs(bb.getBlob(), "test_file"); 
    fileSaver.onwriteend = myOnWriteEnd; 
    

    but window.saveAs doesn't appear to exists.

    Googleing around I've found outdated Google Gears references, but nothing else, maybe because I'm dealing with something too new to have proper documentation ?

    Is there a way to set the filename/mime-type to the first example?

    0 讨论(0)
  • 2021-01-02 16:52

    I think the only way is to call save dialog through flash, see Downloadify library.

    0 讨论(0)
提交回复
热议问题