Endpoint to upload one or more files to the Hello App platform.
HTTP Method: POST
Route: /public-api/v1/files
Headers
api-key: Token generated through API key section.
Request Body
Multipart Form:
files: List of files to be uploaded.
root (optional): Specifies the root directory for file storage. If not provided, the default root is used ("/").
Response
Status Code: 200 OK
Response Body:
{"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"}
Error Responses
400 Bad Request:
If the multipart form is malformed.
500 Internal Server Error:
If there is an internal error during file processing or storage.
Example
Using Fetch API:
consturl='base_url';constinputFile=document.getElementById("file-input");inputFile.addEventListener("change", handleFileSelect);functionhandleFileSelect(event) {constfile=event.target.files[0];if (file) {constformData=newFormData();formData.append("files", file);formData.append("root","/");constoptions= { headers: {'api-key':'your_api_key', }, method:"POST", body: formData, };fetch(url +"/public-api/v1/files", options).then((response) => {if (!response.ok) {thrownewError(`Network error: ${response.status}`); }returnresponse.json(); }).then((data) => {console.log(data); }).catch((error) => {console.error("There was a problem with the Fetch request:", error ); }); }
Using Axios:
constaxios=require('axios');constFormData=require('form-data');constfs=require('fs');consturl='base_url';constfilePath='file_path';//in this case we work from node.js, not a browserfs.readFile(filePath, (err, data) => {if (err) {console.error('Error reading the file:', err);return; }constformData=newFormData();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); });});