Cockpit addon that can import collections data via API. Only accept "json" and "csv" file type.
Most of the code are taken from Cockpit core code here
import.php
.
- Add this repo (
import-collection
) folder inside "addons" folder
- Method -
post
- Route -
/api/import?token={your_token_goes_here}
parameter | type | description |
---|---|---|
entries | file | csv or json file |
collection | string | collection name, this must be the same with the collection name inside Cockpit dashboard |
<form id="myForm">
Import File<br>
<input type="file" name="entries"><br><br>
Collection Name<br>
<input type="text" name="collection"><br>
<button type="submit">Upload</button>
</form>
<script>
const myForm = document.querySelector('#myForm');
myForm.addEventListener("submit", e => {
e.preventDefault();
let data = new FormData(myForm);
fetch('/api/import?token={your_token_goes_here}', {
method: 'POST',
body: data
}).then(e => e.json()).then(res => {
console.log(res)
})
})
</script>