0

I am creating a file providing data got from ajax call using following code.

 $.ajax({
        url: xxx,
        type: "POST",
        data: path,
        contentType: "text/plain; charset=utf-8",
        async: false,
        success: function (data, textStatus, xhr) {
        if (xhr.status == 200) {
              var file = new File({
                name: 'abc.xyz',
                path: 'path/to',
                content: data.content
              });
        } else {         
        }
       }

This operation fails with following browser console error

Uncaught TypeError: Failed to construct 'File': 2 arguments required, but only 1 present.
    at Object.success (BaseTest.js:44)
    at n (jquery.min.js:2)
    at Object.fireWith [as resolveWith] (jquery.min.js:2)
    at w (jquery.min.js:4)
    at d (jquery.min.js:4)
    at Object.send (jquery.min.js:4)
    at Function.ajax (jquery.min.js:4)
    at myFunction (BaseTest.js:32)
    at BaseTest.js:21
    at Function.req.execCb (require.js:1660)

What is the reason for this issue ?

Note: var f = new File([""], "filename.txt", {type: "text/plain", lastModified: date}) is working fine but what is the error with my approach

Malintha
  • 4,512
  • 9
  • 48
  • 82
  • Possible duplicate of [How to instantiate a File object in JavaScript?](http://stackoverflow.com/questions/8390855/how-to-instantiate-a-file-object-in-javascript) – cwallenpoole Jan 19 '17 at 15:06
  • The arguments you pass to `new File` when it works are completely different to the ones when it doesn't work. The error message complains about the arguments. Why not make them match? – Quentin Jan 19 '17 at 15:36

0 Answers0