Upload file with API Endpoints
Create an API Endpoint which includes that field for POST requesting. Also, include urlLink
field for reading to get url of the uploaded file.
curl -X "POST" "https://api.directual.com/good/api/v5/data/test/testfileuploaded?appID=?&sessionID" \
-H 'Content-Type: multipart/form-data; charset=utf-8' \
-F "file="
And these API will return url to your file (if you include urlLink for GET-requesting):
{
"result":[
{
"file":
{
"urlLink":"https://api.directual.com/fileUploaded/evp/faec0620-8a6c-48a8-983b-2bb079536dc0.png"
}
}
],
"status":"OK"
}
// "file" — field name (link to FileUpload data structure)
const uploadHandler = (e) => {
const file = e.target.files[0];
const formData = new FormData();
formData.append(
"file", file
);
api
.structure(fileStorage)
.setData(fileEndpoint, formData,
{
appID: APP_ID,
sessionID: auth.sessionID,
})
.then((response) => {
setResponse(response.result)
setStatus(response.status)
setLoading(false)
})
.catch((e) => {
setLoading(false)
console.log(e.response)
setBadRequest({
httpCode: e.response.status,
msg: e.response.data.msg
})
})
}
<label htmlFor="upload_files">Upload Files</label>
<input type="file" id="upload_files" name="upload_files" onChange={uploadHandler}/>