Skip to content

# API upload routes

AyaNova has several API routes for uploading files.

These routes are all `POST` routes:

- `/api/v{version}/attachment`
- `/api/v{version}/import`
- `/api/v{version}/logo`

Upload routes are not testable from the API explorer console.

Upload routes expect a form to be uploaded with file content disposition (multipart/form-data).

AyaNova limits the size of files uploaded to each of the upload routes documented in the API explorer console comments with those routes.

Here is a sample minimal HTML form that works with AyaNova file routes:

    <!DOCTYPE html>
    <html>
      <head>
        <meta charset="utf-8" />
        <title></title>
        <script
          src="https://code.jquery.com/jquery-3.2.1.min.js"
          integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4="
          crossorigin="anonymous"
        ></script>
        <script type="text/javascript">
          $(document).ready(function () {
            $("#upload").click(function (evt) {
              var fileUpload = $("#files").get(0);
              var files = fileUpload.files;
              var data = new FormData();
              for (var i = 0; i < files.length; i++) {
                data.append(files[i].name, files[i]);
              }

              //Attachment upload route requires further form data to designate
              //the object being attached to by it's type and id:
              //data.append('AttachToAType','2');
              //data.append('AttachToObjectId','200');

              $.ajax({
                type: "POST",
                url: "http://yourserver:7575/api/v8.0/attachment",
                headers: {
                  Authorization: "Bearer JWTTokenHere"
                },
                contentType: false,
                processData: false,
                data: data,
                success: function (message) {
                  alert("upload successful!");
                  console.log(message);
                },
                error: function (error) {
                  console.log(error);
                  alert("There was an error uploading files!");
                }
              });
            });
          });
        </script>
      </head>

      <body>
        <form method="post" enctype="multipart/form-data">
          <input type="file" id="files" name="files" multiple />
          <input type="button" id="upload" value="Upload file(s)" />
        </form>
      </body>
    </html>