Unexpected character at the beginning of file when wrote using blob in javascript

I was using blob to write a file with javascript in the client side. Following is the code snippet I used:

var blob = new Blob(['hello'], {type: "text/plain;charset=utf-8"});
saveAs(blob, "path.m");

Unfortunately, there is a junk character at the beginning of the file as flagged by Matlab:

enter image description here

I don't know what this character is and how Blob is introducing them. But I need to fix it before I can generate an actual matlab .m file.

I request anybody who knows how to fix this to help me.

Thanks.

Upvotes: 2

Views: 270

Answers (1)

I found the solution to this problem. I changed the character set from utf-8 to ISO-8859-1 as follows:

var blob = new Blob(['hello'], {type: "text/plain;charset=ISO-8859-1"});

and it solved the problem.

Upvotes: 1

Related Questions