2

I'm working on a JS feature that will create a text file from some dynamic data, and upload it to a server.

Using the File interface, I was able to dynamically create a file successfully when tested from my personal laptop. Laptop specifications below:

  • Computer/OS: MacBook Pro 10.11.6 (El Capitan)
  • Browsers:
    1. Chrome v63.0.3239.132
    2. FireFox v46.0.1

However, when I try the exact same code on another desktop using a Linux based OS, I receive a security error. Desktop specs below:

  • Computer/OS: Porteus v2.1 (Linux Slackware v14.0)
  • Browser: FireFox v21.0

I realize the Firefox versions are pretty different from one another, but according to the File interface browser compatibility info (or here?), it should work on both.

Heres the exact code I run:

var generatedFile = new File(
  [ 
    "Line One\r\n", 
    "Line Two\r\n" 
  ], 
  "filename.txt", 
  { type: "text/plain" }
);

var form_data = new FormData();

form_data.append('file', generatedFile);

console.log('form_data:', form_data);

And the error is:

  • Exception: The operation is insecure.
  • Code: 18
  • nsresult: 0x80530012

When consulting the Google gods about the above nsresult, I found this other SO post, which states:

After you peel away the layers, the line you are referring to is trying to set input.value on a file input field. This isn't possible for security reasons. The value of a file input field has to be selected by the user, it cannot be set by JavaScript.

However I'm not changing the value of any form input fields. And if this was the reason, that wouldn't explain why it works for newer versions of FF, but not an older version (One would assume the security restriction would be put in place in the later versions, not the other way around).

Any input would help. Thanks!

-J

Justin
  • 1,959
  • 5
  • 22
  • 40

0 Answers0