I am new to JS and I am trying to not include the keys which are null when sent with metadata. Foe ex I should not send tags and owner as they are null but send only filepath as it has value. How can I achieve this?
const metadata = {
filepath: file.name,
tags: [''],
owner: '',
};
const formData = new FormData();
formData.append('file', file);
formData.append('metadata', JSON.stringify(metadata));
axios.post('http://localhost:8000/fileUpload', formData, {
onUploadProgress: (event) => {
}));
},
})
2
Answers
You can try the following way
Then call the function just before supplying the metadata
Cheers.
The tags key is array. You can remove those with the use of filter method.
and feel free to study about js truthy and falsy concept.
https://developer.mozilla.org/en-US/docs/Glossary/Truthy