How build form-data sent MultipartFile to server using upload button

Hi everyone, I'm writing this post because I can't build a form-data with upload button to send the file to the server. The error message I get is  "File not present or  no  multipart boundary was found  or this is not multipart request.", but the file is regularly loaded by the button. ( The type file is .pdf)
Thanks for your help.

This question cannot be answered without you showing the code. Please do.

1 Like

export function button1_click(event, $w) {
if ($w( “#uploadButton1” ).value.length > 0 ) {
$w( “#text11” ).text = "Uploading " + $w( “#uploadButton1” ).value[ 0 ];
$w( “#uploadButton1” ).startUpload()
.then( (uploadedFile) => {
$w( “#text11” ).text = uploadedFile.url;
files($w( “#uploadButton1” ).value[ 0 ]);
})
. catch ( (uploadError) => {
$w( “#text11” ).text = “File upload error” ;
console.log( "File upload error: " + uploadError.errorCode);
console.log(uploadError.errorDescription);
});
}
else {
$w( “#text11” ).text = “Please choose a file to upload.” ;
}
}

function files( x){
let formdata = new FormData();
formdata.append( ‘file’ , x);
fetch( ‘https//:…’ ,{
method: ‘post’ ,
headers: {
‘Content-Type’ : ‘multipart/form-data’ ,
},
body: formdata
}).then(response => {
//something
}). catch (err => {
console.log(err)
}) ;
}

This code not work, and i get error “File not present” or no multipart boundary was found or this is not multipart request… dunno i have to do again :frowning:

i post code below… thank you so much for help me…

i still wait … someone can help me ?

Try to send the header like that:
headers : { … formData .getHeaders() },