Uploader problems. How to send the uploader file



  • Hi,
    A question about the uploader.
    I need to post the images to a URL that will rename the uploaded file and return the full path.

    I’m using upload-factory and axios

    But I’m having problems understanding exactly how to pass the file to axios as if it was a input type file.
    Basically I need to make it as If I’m sending a form with a single input file like this:

    <input type="file" name="banner">
    

    This is the component:

    <q-uploader
            url=""
            extensions=".gif,.jpg,.jpeg,.png"
            :filter="filterFiles"
            :upload-factory="uploadFile"
    

    This is the upload method, but I keep getting an error.

    uploadFile (file, updateProgress) {
          const formData = new FormData()
          formData .set('banner', file)
          var headers = {
            'Content-Type': 'multipart/form-data'
          }
          axios.post('http://someurl/uploadFile', formData , headers)
            .then(function (response) {
              console.log(response)
            })
            .catch(function (response) {
              console.log(response)
            })
        }
    

    If I post a plain html form with method=“post” enctype=“multipart/form-data” and a

    <input type="file" name="banner">
    

    I get my OK response from the server with the processed/uploaded image URL


Log in to reply