Acode icon indicating copy to clipboard operation
Acode copied to clipboard

How to create and save a file from the inappbrowser.

Open MagTun opened this issue 3 years ago • 3 comments

I am running a custom HTML in the inappbrowser . I am able to load the content of a text file via fetch and FileReader into a textarea where I can modify it. Now I would like to save the modified content back into the file (or another file if it's not possible).

I have tried many proposed answer like this one:

    let a = document.createElement('a');
    a.href = "data:text/plain;charset=utf-8," + encodeURIComponent("some text");
    a.download = 'name.txt';
    a.click()

or this one:

    var blob = new Blob(["some text"], {
        "type": "text/plain"
    });
    var a = document.createElement("a");
    a.download = "name.txt";
    a.href = (window.URL || window.webkitURL || window || {}).createObjectURL(blob);
    document.body.appendChild(a);
    a.click();
    document.body.removeChild(a);

But none of them work.

Because these scripts work in my default android browser, I thought about doing the download in another way: sending a request to open a link/blob into the default browser and then let this default browser do the download. So I tried this:

    var blob = new Blob(["aaaa"], {
        type: 'text/plain'
    });
    var blobUrl = URL.createObjectURL(blob);
    window.open(blobUrl, '_system', 'location=yes');

But here again it's not working. Also if I hardcode this in the html: <a href="#" onclick="window.open(encodeURI('https://google.com/'),'_system')">link</a>; the link is actually open in the inappbrowser not in the external default browser.

Any idea how I can create a file?

Also, I found one way of making it work in Acode but it is not suited to my need: in the settings of Acode I can choose to preview with the browser instead of the inappbrowser (but I need to use the inappbrowser).With the browser the file download is working, but once again, I can't use it that way.

Thanks for your help!

MagTun avatar Jun 30 '21 19:06 MagTun

Use Stack Overflow for this kinds of questions. This is not related to the repository itself.

fabriziodsp-ransom avatar Jul 14 '21 23:07 fabriziodsp-ransom

@fabriziodsp-ransom , I actually did post the question on stackoverflow several days before I posted here but I got not help there. Also it it related to the repository because the code works on a regular browser. So there is something in Acode/Cordora that prevents it from working.

But you are right I should have reframe the question to make it more repository related

MagTun avatar Jul 17 '21 10:07 MagTun

@fabriziodsp-ransom , I actually did post the question on stackoverflow several days before I posted here but I got not help there. Also it it related to the repository because the code works on a regular browser. So there is something in Acode/Cordora that prevents it from working.

But you are right I should have reframe the question to make it more repository related

@MagTun Actually, the app is failing to build. It's an issue that has been already shown on the readme file. You can see that there is a special tag that says: "build: fail". The owner has to fix it

fabriziodsp-ransom avatar Jul 17 '21 12:07 fabriziodsp-ransom