0

(Non frontender here so excuse my total ignorance here)

I have a multipart form with a file selector, the form and the file should be sent to a POST endpoint in my backend.

How do I send this form "behind the scenes" so to say, without redirecting the entire browser tab to the target URL?

I've found this post: https://laracasts.com/discuss/channels/vue/submit-serialized-form-data-with-vue?page=1

But that does not address file inputs.

What would be the proper way forward?

1 Answer 1

3

had this issue a few months ago. the problem was that the file wasn't attached to the javascript formData object and you need to do so manually before you submit formDate to the backend with whatever http-client you're using

try to create a new data property called file and then in your file input tag write v-model="file" so it has that file

then before the post request try to attach that file property to the formData object maybe with something like that

let formData = new FormData();
formData.append('file', this.file);

It worked for me when I was trying to solve that issue and it should work with you too. if it doesn't, just let me know

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.