Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't upload file to server #38

Closed
jay7793 opened this issue Jun 22, 2018 · 4 comments
Closed

Can't upload file to server #38

jay7793 opened this issue Jun 22, 2018 · 4 comments

Comments

@jay7793
Copy link

jay7793 commented Jun 22, 2018

Hello
I'm having trouble uploading form file to server. I follow this example. I do not know what's wrong with my code. Please help.

This is my code for post to server (When clicked Submit button)

update() {
   this.form
   .post('/settings/profile', {
      // Transform form data to FormData
      transformRequest: [
        function(data) {
          return objectToFormData(data)
        }
      ]
    })
   .then(({ data }) => {
     this.$store.dispatch('auth/updateProfile', { data })
   })
}

Before upload to server I monitor the form object using console.log() the avatar field contain file data.

image

Then upload the file to the server, each field works correctly except for the avatar field (it is empty).

image

I don't understand where the data is missing

Thank you.

@kullarkert
Copy link

Try with this.form.submit not this.form.post

@christiancazu
Copy link

Try with this.form.submit not this.form.post

i can't do it work with put or patch, when i send the request arrives empty to my backend

@jimohalloran
Copy link

Same issue here. Using form.submit instead of form.post works fine for me. But if I try this with form.submit('patch' my backend doesn't receive the form data.

@cretueusebiu
Copy link
Owner

See my comment #54 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants