Freemaster, javascript write to file

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Freemaster, javascript write to file

1,007 Views
Tazio
Contributor II

Dear SIrs,

I need to write to a file in a JSON script with Chromium rendering engine,.

I am currently using this code:

async function Save_OnClick()
{
   try
   {

      let txt;

      const handle = await showSaveFilePicker({
           suggestedName: "XXXs.txt",
           types: [
           {
                     description: "Text file",
                     accept: { "text/plain": [".txt"] },
                     },
                     ],
           });

      txt = await prepareBackupTxt();

      const writableStream = await handle.createWritable();
      await writableStream.write(txt);
      await writableStream.close();
   }
   catch(ex)
   {
      console.log('ex: ' + ex);
   }
}

it works as expected in:
- a chrome browser
- in freemaster with edge rendering engine

In the internal chrome engine the following exception is returned:

NotAllowedError: The request is not allowed by the user agent or the platform in the current context.

How can i allow file writes in the internal chromium?

Thank you and best regards

Tazio

0 Kudos
4 Replies

991 Views
MichalH
NXP Apps Support
NXP Apps Support

Dear Tazio,

we will need to retest your case, but most probably this is caused by limited access rights of the anonymous "sandbox" context used by FreeMASTER inside the CEF/Chromium view. 

You can consider to use the FreeMASTER's own JSON-RPC API to access the text files (LocalFileOpen, LocalFileClose, LocalFileReadString, LocalFileReadString). Refer to FreeMASTER User Guide for more details.

Reagrds,
Michal

0 Kudos

938 Views
Tazio
Contributor II

Dear Michael,

thank you for youz quick reply.

I have tried to use the API to access the files without succes.

The main problem is that i need to access a file with an absolute path (chosen via a file save dialog) but the API supports only relative paths.

Best Regards

Tazio

0 Kudos

331 Views
MichalH
NXP Apps Support
NXP Apps Support

Dear Tazio,

I just wanted to check with you status of this issue. Has there been any progress on your side?

Unfortunately we were not able to identify the root cause. It seems the CEF component prevents to use "createWritable" on the handle returned by "showSafeFilePicker". It also prevents the client script to "requestPermission" explicitly on that handle with "mode = readwrite" options. The same with read-only mode works well.

Internally, the CEF shall give chance to override the permission using its CefPermissionHandler, but we had not success in this as well.

Thanks,
Michal

 

0 Kudos

801 Views
MichalH
NXP Apps Support
NXP Apps Support

Understood, I'm sorry for the inconvenience. We will examine this issue more and will address the issue in the next version.

Thank you,
Michal

0 Kudos