I am trying to use server action to save file, but i dont understand, how i get file Buffer from formdata.
client call->
const handleUpload = async () => {
setLoading(true);
const formData = new FormData();
formData.append('file', file);
const uploadResponse = await uploadFile(formData); // server action
setLoading(false);
inputFile.current.value = null;
setFile(undefined);
};
server action ->
export const uploadFile = async (formData: FormData) => {
const file = formData.get('file');
console.log('uploadFile');
console.log(file);
/**
File {
size: 612726,
type: 'application/pdf',
name: '2952940407.pdf',
lastModified: 1716839583344
}
*/
fs.writeFile('./tmp/'+file.name, file.data, (err: any): any => {
if (err) throw err;
console.log('Results Received');
});
return;
};
Server action isnt working like that?