Huemul / trae

:postbox: Minimalistic Fetch based HTTP client
https://trae.online
MIT License
257 stars 14 forks source link

multipart form data? #69

Open lopezchr opened 7 years ago

lopezchr commented 7 years ago

I've tryed to use this library to send a multipart form data. I'm using vuejs and javascript FormData but it does not work. I've using axios semantic like this: https://scotch.io/tutorials/how-to-handle-file-uploads-in-vue-2

var formData = new FormData()
formData.append('fieldName', File)
trae.post(url, formData)

How can I solve this?

gillchristian commented 7 years ago

Hello @lopezchr could you please add the error you get ?

I will take a look

lopezchr commented 7 years ago

The request send an application/json content-type. Now, if I change the content type manually...

    return trae.post(url, formData, {
      headers: {
        Authorization: `Bearer ${token}`
        'Content-Type': 'multipart/form-data'
      }
    })

I had this in my php api.

Missing boundary in multipart/form-data POST data in Unknown on line 0

HectorNJ commented 7 years ago

try this!

return trae.post(url, formData, {
   headers: {
    Authorization: `Bearer ${token}`
    'Content-Type': ''
  }
})
thejams commented 6 years ago

did this work ?, i am having a similar problem, only that the trae library does not give me any error but the server does not receive any multipart-form-data

crzurita commented 6 years ago

I got the same problem. In the docs: // The Headers object associated with the request headers: { 'Content-Type': 'application/json' // Default header for methods with body (patch, post & put) 'X-My-Custom-Header': 'foo-bar' },

I tried override Content-Type: ' ' but doesn't work! I have this response: content

It seems like still sending with header Content-Type: 'application/json'

crzurita commented 6 years ago

I was watching this method:

_initMethodsWithBody() {
    const defaultConf = {
      headers: { 'Content-Type': 'application/json' },
    }
    ;['post', 'put', 'patch'].forEach((method) => {
      this._config.set({ [method]: defaultConf })

      this[method] = (path, body = {}, config = {}) => {
        const url = formatUrl(this._baseUrl, path, config.params)
        const mergedConfig = this._config.merge(config, { body, method, url })

        return this._fetch(url, mergedConfig)
      }
    })
}

I just change:

const defaultConf = { headers: { 'Content-Type': 'application/json' }, }

By this:

const defaultConf = { headers: {}, }

And works because is passing headers: empty by default now.

cmoralesheras commented 6 years ago

Tengo el mismo problema, no puedo subir imagenes, alguna solucion?

gillchristian commented 6 years ago

@viciotec looks like @clochi's is right, I will work on it as soon as I can.

cmoralesheras commented 6 years ago

@viciotec parece que @clochi 's tiene razón, trabajaré en ello tan pronto como pueda.

Ah pasado mucho tiempo y sigue sin solucion

gillchristian commented 5 years ago

@cmoralesheras eres bienvenido a colaborar en la librería, nosotros lo hacemos en nuestro tiempo libre

En el momento empezamos a trabajar en la v2 y nos gustaría resolver en issue ahí