1

I want to Upload File To Spring boot backend , How should I send Formdata as requestparam in postrequest, i tried following code

angular service class code

let headers=new HttpHeaders({
               'Content-Type="multipart/form-data'
                })
                const formData:FormData=new FormData();
                formdata.apend('file',file);
                 return this.http.post(uploaadfile,{params:{
                 file:formData,
                  contracttemplateid:28
                  }},options);

spring boot controller code

@postmapping
uploadfile(@requestparam("file") MultipartFile 
file,@requestparam("contracttemplateid") long id)
{
}
1

1 Answer 1

0
Uploadfile(formData: FormData, FileName: string){    
   return this.http.post('URL',formData,{'params': {filename : FileName}});
  }

let fd = new FormData();
let FileName = "FileName";

fd.append(SeletedFile, FileName)

Uploadfile(fd,FileName);
Sign up to request clarification or add additional context in comments.

1 Comment

removed http options and used proxy config.json to avoid cors issue that worked for me...im accepting the answer

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.