59 lines
2.2 KiB
HTML
59 lines
2.2 KiB
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]);
|
|
}
|
|
|
|
//attachment test
|
|
data.append('AttachToObjectType','2');//object 2 is widget
|
|
data.append('AttachToObjectId','200');//there should normally always be a widget with id 1
|
|
|
|
$.ajax({
|
|
type: "POST",
|
|
url: "http://localhost:7575/api/v8.0/Attachment",
|
|
headers: {
|
|
Authorization: "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpYXQiOiIxNTIxNTY5ODE5IiwiZXhwIjoiMTUyNDE2MTgxOSIsImlzcyI6IkF5YU5vdmEiLCJpZCI6IjEifQ.4PzkzZNYK5mJkbfCHGQ2N2248atAvvcDgApoz65oIC0"
|
|
},
|
|
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="file" accept=".zip,application/zip" id="files" name="files" multiple /> -->
|
|
<input type="button" id="upload" value="Upload file(s)" />
|
|
|
|
|
|
|
|
|
|
</form>
|
|
|
|
</body>
|
|
|
|
</html> |