# \[SOLVED\] Which is the best practice for sending a file to a custom node form?

**URL:** <https://discourse.nodered.org/t/solved-which-is-the-best-practice-for-sending-a-file-to-a-custom-node-form/11508>\
**Category:** General\
**Created:** [24 May 2019 15:17 UTC](https://discourse.nodered.org/t/solved-which-is-the-best-practice-for-sending-a-file-to-a-custom-node-form/11508 "2019-05-24T15:17:17Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![gbove731](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gbove731/32/8128_2.png) [@gbove731](https://discourse.nodered.org/u/gbove731)\
**Post date:** [24 May 2019 15:17 UTC](https://discourse.nodered.org/t/solved-which-is-the-best-practice-for-sending-a-file-to-a-custom-node-form/11508/1 "2019-05-24T15:17:17Z")

</div>

Which is the best practice for sending a file to a custom node form?

In my custom node I would like to allow to send a file to a custom end point (made via RED.admin.post) who parse the file and output a json to the caller.

Is there a way to do this?

EDIT: I solved in this way:

In template .html file

```auto
<script type="text/x-red" data-template-name="...">

  <form id="myForm">
    <input id="myFile" type="file" name="fileToUpload">
    <input id="file-submit" type="submit" value="Import data from file" name="submit">
  </form>
...

```

```auto
        oneditprepare: function () {
            $('#file-submit').click(function (e) {
                var fd = new FormData();
                fd.append('file', $('#myFile')[0].files[0]);
                var file = fd.get('file');
                var blb = file.slice();
                var reader = new FileReader();
                // This fires after the blob has been read/loaded.
                reader.addEventListener('loadend', (e) => {
                    var fileData = e.srcElement.result;
                    $.ajax({
                        url: '/file-upload',
                        data: { fileData: fileData},
                        method: 'POST',
                        success: function (data) {
                            populateForm(data);
                        }
                    });
                });
                // Start reading the blob as text.
                reader.readAsBinaryString(blb);
            });

```
