This commit is contained in:
2022-01-17 18:40:12 +00:00
parent 1f33c63fda
commit b7d621d41f
5 changed files with 178 additions and 65 deletions

View File

@@ -4,75 +4,72 @@ AyaNova has several API routes for uploading files.
These routes are all `POST` routes:
- `/api/v{version}/Attachment`
- `/api/v{version}/ImportAyaNova7`
- `/api/v{version}/Restore`
- `/api/v{version}/attachment`
- `/api/v{version}/import`
- `/api/v{version}/logo`
Upload routes are not testable from the API explorer.
Upload routes are not testable from the [API explorer console](api-console.md).
Upload routes expect a form to be uploaded with file content disposition (multipart/form-data).
AyaNova will allow a maximum of 12gb per file upload for "Utility" routes such as restore and import routes.
User file routes such as attachments may have a smaller limit, see the User documentation section for those features for limit details.
AyaNova limits the size of files uploaded to each of the upload routes documented in the [API explorer console](api-console.md) comments with those routes.
Here is a sample minimal HTML form that works with AyaNova file routes:
```html
<!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]);
}
<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');
//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>
$.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>
<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>
```