Freemaster, javascript write to file

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

Freemaster, javascript write to file

1,048 次查看
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

标记 (3)
0 项奖励
回复
4 回复数

1,032 次查看
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 项奖励
回复

979 次查看
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 项奖励
回复

372 次查看
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 项奖励
回复

842 次查看
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 项奖励
回复