I've been trying to send a Vcard file with React and Axios on my Symfony API for a few hours now but I can't get a file POST on symfony.
I make my request by retrieving my Vcard file with a file type input, here is my code:
submitFile = (values, actions) => {
axios({
method: 'post',
url: process.env.REACT_APP_SERVER_NAME+"/api/vcard/parser",
headers: {
'Content-Type': 'multipart/form-data',
'Accept': 'multipart/form-data',
Authorization: "Bearer " + Cookies.get("BEARER")
},
data: {
file: values
}
})
when I do a dd(Request) on symfony what I get in this case I have this:
+request: Symfony\Component\HttpFoundation\InputBag {#100
#parameters: array:1 [
"file_file" => "C:\fakepath\monfichier.vcf"
]
}
If I make a request with Postmann and also my dd(Request) I get the expected result and I can retrieve an element of type Request->files:
+files: Symfony\Component\HttpFoundation\FileBag {#93
#parameters: array:1 [
"file" => Symfony\Component\HttpFoundation\File\UploadedFile {#92
-test: false
-originalName: "monfichier.vcf"
-mimeType: "text/x-vcard"
-error: 0
path: "C:\wamp64\tmp"
filename: "phpA068.tmp"
basename: "phpA068.tmp"
pathname: "C:\wamp64\tmp\phpA068.tmp"
extension: "tmp"
realPath: "C:\wamp64\tmp\phpA068.tmp"
aTime: 2022-10-04 05:11:21
mTime: 2022-10-04 05:11:21
cTime: 2022-10-04 05:11:21
inode: 281474978677051
size: 461
perms: 0100666
owner: 0
group: 0
type: "file"
writable: true
readable: true
executable: false
file: true
dir: false
link: false
linkTarget: "C:\wamp64\tmp\phpA068.tmp"
}
]
}
Can you give me a little idea of my Axios configuration to make it work? I tried to pass my data through a FormData but without success either.
Thank you in advance
A+ Julien