Endpoint to upload one or more files to the Hello App platform.
{
"status": "success",
"files": [
{
"ID": 1,
"Name": "example.txt",
"UID": "unique_id",
"Root": "/",
"CID": "QmXqwe12...",
"Mime": "text/plain",
"Size": 1024,
"EncryptionStatus": "public",
"CreatedAt": "2023-01-01T12:00:00Z",
"UpdatedAt": "2023-01-01T12:00:00Z"
}
// ... additional file objects if multiple files are uploaded
],
"firstRootUID": "first_root_unique_id"
}
const url = 'base_url';
const inputFile = document.getElementById("file-input");
inputFile.addEventListener("change", handleFileSelect);
function handleFileSelect(event) {
const file = event.target.files[0];
if (file) {
const formData = new FormData();
formData.append("files", file);
formData.append("root", "/");
const options = {
headers: {
'api-key': 'your_api_key',
},
method: "POST",
body: formData,
};
fetch(url + "/public-api/v1/files", options)
.then((response) => {
if (!response.ok) {
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';
const filePath = 'file_path';
//in this case we work from node.js, not a browser
fs.readFile(filePath, (err, data) => {
if (err) {
console.error('Error reading the file:', err);
return;
}
const formData = new FormData();
formData.append('files', data, {filename: 'name of the file'});
formData.append('root', '/');
axios.post(`${url}/public-api/v1/files`, formData, {
headers: {
...formData.getHeaders(),
'api-key': 'your_api_key',
},
})
.then((response) => {
console.log(response.data);
})
.catch((error) => {
console.error('There was a problem with the Axios request:', error);
});
});