You can post axios data by using FormData() like:
var bodyFormData = new FormData();
And then add the fields to the form you want to send:
bodyFormData.append('userName', 'Fred');
If you are uploading images, you may want to use .append
bodyFormData.append('image', imageFile);
And then you can use axios post method (You can amend it accordingly)
axios({ method: "post", url: "myurl", data: bodyFormData, headers: { "Content-Type": "multipart/form-data" }, }) .then(function (response) { //handle success console.log(response); }) .catch(function (response) { //handle error console.log(response); });
Related GitHub issue:
Can’t get a .post with ‘Content-Type’: ‘multipart/form-data’ to work @ axios/axios
Related Posts:
- When to use componentWillReceiveProps lifecycle method?
- What is mapDispatchToProps?
- how to delete a single item using axios in react
- Axios having CORS issue
- React-Redux: Actions must be plain objects. Use custom middleware for async actions
- How to use onClick event on react Link component?
- What is localhost 3000?
- What is localhost 3000?
- MenuIcon not found in material-ui/icons
- How To Add My Own Svg Image Just Like Logo Is Shown By Default In Create-React-App
- Error : Cannot read property ‘map’ of undefined
- Error : Cannot read property ‘map’ of undefined
- How do I reference a local image in React?
- How to use clsx in React
- How to use clsx in React
- Axios Delete request with body and headers?
- Understanding React-Redux and mapStateToProps()
- Understanding the React Hooks ‘exhaustive-deps’ lint rule
- Error: ‘node-sass’ version 5.0.0 is incompatible with ^4.0.0
- Console.log() isn’t logging in ReactJS
- Reactjs this.setState is not a function error
- How to fix missing dependency warning when using useEffect React Hook
- When to use React setState callback
- What exactly is the ‘react-scripts start’ command?
- Adding an .env file to React Project
- react-scripts: command not found
- Component definition is missing display name react/display-name
- What is withRouter for in react-router-dom?
- React Context vs React Redux, when should I use each one?
- How to include bootstrap css and js in reactjs app?
- When to use useImperativeHandle, useLayoutEffect, and useDebugValue
- What does this “react-scripts eject” command do?
- React – expressions must have one parent element?
- Can you force a React component to rerender without calling setState?
- Fetching JSON returns error Uncaught (in promise) SyntaxError: Unexpected token < in JSON at position 0 and status code 304: Not Modified
- Is using async componentDidMount() good?
- Support for the experimental syntax ‘classProperties’ isn’t currently enabled
- Inserting the iframe into react component
- How to use callback with useState hook in react
- How to use callback with useState hook in react
- How to resolve “Cannot use import statement outside a module” in jest
- How to use switch statement inside a React component?
- forEach() in React JSX does not output any HTML
- Scroll to the top of the page after render in react.js
- What does “isomorphic React” mean?
- How to declare a global variable in React?
- How to use onload in react?
- Local package.json exists, but node_modules missing
- Why am I getting Warning: Functions are not valid as a React child?
- Access Control Origin Header error using Axios
- Uncaught Error: Invariant Violation: Element type is invalid: expected a string (for built-in components) or a class/function but got: object
- What is the difference between .ts and .tsx extensions. Both are used as extensions for typescript files in react. So where should we use them?
- This.props.dispatch not a function – React-Redux
- webpackJsonp is not defined
- How to set a default value in react-select
- Invalid Host Header when ngrok tries to connect to React dev server
- ReactNative: how to center text?
- How do I avoid ‘Function components cannot be given refs’ when using react-router-dom?
- Invariant Violation: Could not find “store” in either the context or props of “Connect(SportsDatabase)”
- react-router vs react-router-dom, when to use one or the other?
- React Props is Not Defined
- ReactJs CreateClass is not a function
- onKeyDown event not working on divs in React
- React.createElement: type is invalid — expected a string
- Read the current full URL with React?
- ‘React’ must be in scope when using JSX react/react-in-jsx-scope?
- Show or hide element in React
- React statics with ES6 classes
- componentDidMount() not being called when react component is mounted
- Invariant Violation: Objects are not valid as a React child
- React.js inline style best practices [closed]
- Understanding unique keys for array children in React.js
- Difference between npx and npm?
- Loop inside React JSX
- Can’t resolve module (not found) in React.js
- Parse Error: Adjacent JSX elements must be wrapped in an enclosing tag
- In reactJS, how to copy text to clipboard?
- What is prevState in ReactJS? [duplicate]
- React with ES7: Uncaught TypeError: Cannot read property ‘state’ of undefined
- Setting a backgroundImage With React Inline Styles
- React – TypeError: Cannot read property ‘props’ of undefined
- React Navigation back() and goBack() not working
- How to import image (.svg, .png ) in a React Component
- React Error: Target Container is not a DOM Element
- How to handle the `onKeyPress` event in ReactJS?
- What does “export default” do in JSX?
- Uncaught Invariant Violation: Too many re-renders. React limits the number of renders to prevent an infinite loop
- Warning: findDOMNode is deprecated in StrictMode. findDOMNode was passed an instance of Transition which is inside StrictMode
- React.js – Can’t read property of undefined
- React’s setState method with prevState argument
- How to clear react-native cache?
- Can’t perform a React state update on an unmounted component
- React-Router : What is the purpose of IndexRoute?
- command not found: jest
- ReactJS – .JS vs .JSX
- ReactJS: Maximum update depth exceeded error
- React, Uncaught ReferenceError: ReactDOM is not defined
- How to get parameter value from query string?
- Invariant Violation: _registerComponent(…): Target container is not a DOM element
- What does “export default” do in JSX?