admin管理员组文章数量:1356356
I have been trying to upload a file with form data using axios in vue js with laravel backend. There are few solutions out there but I am not being able to make them work.
So here what I am trying to do. Here is my data in vue js and I am binding them with v-model.My form submission method and it's code
let formData = new FormData();
var file = document.querySelector('#report');
formData.append("file", file.files[0]);
formData.append('someName','someValue');
axios({
method: 'put',
url: self.sl+'/seller/upflv',
data: formData,
})
In laravel backend I am loggin using
\Log::info($request->all());
And I get an empty array in my log file.
Here is what I can see in my chrome network
------WebKitFormBoundary0Q7B39baNw6AJXDA
Content-Disposition: form-data; name="file"; filename="d.PNG"
Content-Type: image/png
------WebKitFormBoundary0Q7B39baNw6AJXDA
someValue
------WebKitFormBoundary0Q7B39baNw6AJXDA--
Any help or explanation would be extremely helpful. Thank you.
I have been trying to upload a file with form data using axios in vue js with laravel backend. There are few solutions out there but I am not being able to make them work.
So here what I am trying to do. Here is my data in vue js and I am binding them with v-model.My form submission method and it's code
let formData = new FormData();
var file = document.querySelector('#report');
formData.append("file", file.files[0]);
formData.append('someName','someValue');
axios({
method: 'put',
url: self.sl+'/seller/upflv',
data: formData,
})
In laravel backend I am loggin using
\Log::info($request->all());
And I get an empty array in my log file.
Here is what I can see in my chrome network
------WebKitFormBoundary0Q7B39baNw6AJXDA
Content-Disposition: form-data; name="file"; filename="d.PNG"
Content-Type: image/png
------WebKitFormBoundary0Q7B39baNw6AJXDA
someValue
------WebKitFormBoundary0Q7B39baNw6AJXDA--
Any help or explanation would be extremely helpful. Thank you.
Share Improve this question asked Jan 15, 2018 at 10:02 Hkm SadekHkm Sadek 3,20912 gold badges51 silver badges105 bronze badges 3-
Try to log
$request->hasFile("file");
. – Sérgio Reis Commented Jan 15, 2018 at 10:11 - But what about my input? sameName? – Hkm Sadek Commented Jan 15, 2018 at 10:15
- yes, it's empty – Hkm Sadek Commented Jan 15, 2018 at 10:16
1 Answer
Reset to default 11Ran into a problem like that some time ago.
check this https://github./laravel/framework/issues/13457#issuement-239451567
Try to send it like this:
let formData = new FormData();
var file = document.querySelector('#report');
formData.append("file", file.files[0]);
formData.append('someName','someValue');
formData.append('_method', 'PUT'); // ADD THIS LINE
axios({
method: 'post', //CHANGE TO POST
url: self.sl+'/seller/upflv',
data: formData,
})
本文标签:
版权声明:本文标题:javascript - Uploading file and input data using axios in laravel and vue - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743959459a2568752.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论