Endpoint to update information about a specific file based on its UID.
const url = 'base_url/public-api/v1/files/your_file_uid';
const apiKey = 'your_api_key';
const inputFile = document.getElementById("file-input");
inputFile.addEventListener("change", handleFileUpdate);
function handleFileUpdate(event) {
const file = event.target.files[0];
if (file) {
const formData = new FormData();
formData.append("file", file);
formData.append("root", "/");
const options = {
headers: {
'api-key': apiKey,
},
method: "PUT",
body: formData,
};
fetch(url, options)
.then((response) => {
if (!response.ok) {
if (response.status === 404) {
console.error('File not found.');
} else {
throw new Error(`Network error: ${response.status}`);
}
}
return response.json();
})
.then((data) => {
console.log(data);
})
.catch((error) => {
console.error('There was a problem with the Fetch request:', error);
});
}
}
const axios = require('axios');
const FormData = require('form-data');
const fs = require('fs');
const url = 'base_url/public-api/v1/files/your_file_uid';
const apiKey = 'your_api_key';
const filePath = 'file_path';
fs.readFile(filePath, (err, data) => {
if (err) {
console.error('Error reading the file:', err);
return;
}
const formData = new FormData();
formData.append('file', data, { filename: 'name of the file' });
formData.append('root', '/');
axios.put(url, formData, {
headers: {
...formData.getHeaders(),
'api-key': apiKey,
},
})
.then((response) => {
console.log(response.data);
})
.catch((error) => {
if (error.response.status === 404) {
console.error('File not found.');
} else {
console.error('There was a problem with the Axios request:', error);
}
});
});