Skip to content

Fixed isFormData predicate;#4413

Merged
jasonsaayman merged 2 commits intoaxios:masterfrom
DigitalBrainJS:fix/isFormData
Feb 2, 2022
Merged

Fixed isFormData predicate;#4413
jasonsaayman merged 2 commits intoaxios:masterfrom
DigitalBrainJS:fix/isFormData

Conversation

@DigitalBrainJS
Copy link
Copy Markdown
Collaborator

@DigitalBrainJS DigitalBrainJS commented Jan 21, 2022

Browser example:

const axios= require('axios');

axios.post('https://postman-echo.com/post', {x: 1}, {
  headers: {
    'Content-Type': 'multipart/form-data'
  }
}).then(({data})=> console.log(data));

Node.js example

const axios= require('axios');
var FormData = require('form-data');

// OR
// axios.defaults.env.FormData= FormData;

axios.post('https://postman-echo.com/post', {x: 1}, {
  headers: {
    'Content-Type': 'multipart/form-data'
  },

  env: {  // OR
    FormData
  }
}).then(({data})=> console.log(data));

Response:

{
  args: {},
  data: {},
  files: {},
  form: { x: '1' },
  headers: {
    'x-forwarded-proto': 'https',
    'x-forwarded-port': '443',
    host: 'postman-echo.com',
    'x-amzn-trace-id': 'Root=1-61eb41dc-5eb39a192efeea3a65d9e624',
    'content-length': '157',
    accept: 'application/json, text/plain, */*',
    'content-type': 'multipart/form-data; boundary=--------------------------086549356411608332106674',
    'user-agent': 'axios/0.25.0'
  },
  json: null,
  url: 'https://postman-echo.com/post'
}

Added support for automatic object serialization to FormData if `Content-Type` is `multipart/form-data`;
Added support for FormData to be overloaded using `config.env.FormData` option;
Added support for FormData in node.js environment through `form-data` package;
@carpben
Copy link
Copy Markdown
Contributor

carpben commented Feb 5, 2022

I must say I'm a bit concerned about this PR.
Especially since it was added with out any tests. @jasonsaayman I suggest waiting with releasing the next version until proper tests are added.

jasonsaayman added a commit that referenced this pull request Feb 13, 2022
jasonsaayman added a commit that referenced this pull request Feb 13, 2022
DigitalBrainJS added a commit to DigitalBrainJS/axios that referenced this pull request Feb 15, 2022
Added support for automatic object serialization to FormData if `Content-Type` is `multipart/form-data`;
Added support for FormData to be overloaded using `config.env.FormData` option;
Added support for FormData in node.js environment using `form-data` package;

(cherry picked from commit 73e3bdb)
jasonsaayman pushed a commit that referenced this pull request Mar 14, 2022
* Fixed isFormData predicate;
Added support for automatic object serialization to FormData if `Content-Type` is `multipart/form-data`;
Added support for FormData to be overloaded using `config.env.FormData` option;
Added support for FormData in node.js environment through `form-data` package;

* Added the `form-data` package as a dependency for the server build;
Added tests for FormData payload;

* Added FormData automatic serialization section;
Refactored cancellation section;

* Reworked toFormData helper;
Expose toFormData helper as a static method;
Refactored transform request;
Added kindOf, kindOfTest, endsWith, isTypedArray util;
Refactored utils.js to use kindOf for tests;

* Fixed isFormData predicate; (#4413)

Added support for automatic object serialization to FormData if `Content-Type` is `multipart/form-data`;
Added support for FormData to be overloaded using `config.env.FormData` option;
Added support for FormData in node.js environment using `form-data` package;

(cherry picked from commit 73e3bdb)

* Added shortcut methods `postForm`, `putForm`, `patchForm` to submit a Form;
Added ability to submit FileList object as a FormData;
Updated README.md;

* Updated README.md;
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

Successfully merging this pull request may close these issues.

3 participants