plugins-workspace: [fs][v2] writeFile fails with error "unexpected invoke body"

writeFile is failing on Linux.

I call it like this:

import { save } from '@tauri-apps/plugin-dialog';
import { writeFile } from '@tauri-apps/plugin-fs';

const path = await save();
await writeFile(path, new TextEncoder().encode('a'));

Error:

unexpected invoke body

writeTextFile worked fine though.

package.json "@tauri-apps/plugin-fs": "^2.0.0-beta.5"

cargo.toml tauri-plugin-fs = "2.0.0-beta.9"

permissions: "fs:allow-write", "fs:allow-write-file", "fs:allow-write-text-file",

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 4
  • Comments: 23 (6 by maintainers)

Most upvoted comments

Could you please provide a minimal repro

Maybe, I found the solution.

The save path can only be in English, not Chinese, otherwise it will cause JSON error. I wonder if you can fix it in subsequent versions, we will be very grateful to you.

I have do serval experiments, but I got same error unexpected invoke body. Also, I have updated all package, the version shown below:

"@tauri-apps/plugin-http": "^2.0.0-beta.7"

tauri-plugin-fs = "2.0.0-beta.10"

I had the same problem as you when I was saving an excel file.

Error:

unexpected invoke body

I am sure that I get the correct http response body, but I can not save it as a file.

My code:

axios.get(url, {
  responseType: 'arraybuffer',
}).then((response) => {
  writeFile(savePath, response.data);
});

But when I save a image by using above code, it is correct. I am very confused about this.