score:0
#api
import axios;
const avatarupload = (data, uuid) => {
return axios.post(`endpoint/`, data).then(
(res) => res,
(error) => error.response
);
};
#store
getavatar = async (data, cb) => {
const uuid = localstorageservice.getuuid();
const resp = await avatarupload(data, uuid);
if (resp.status === 200) {
this.setmessage('successfully updated');
this.setuser(resp.data);
cb();
} else {
cb(resp.data.error);
}
this.setpicloading(false);
};
#web page
const handlefilechange = async (event) => {
const data = new formdata();
data.append('avatar', event.target.files[0]);
getavatar(data, (error) => {
seterror(error);
});
setfader(1);
};
<form.group controlid='formbasictext'>
<button
classname='primary'
type='button'
onclick={handlechangeavatarclick}
>
change avatar
</button>
<form.control
style={{ display: 'none' }}
type='file'
ref={hiddenfileinput}
onchange={handlefilechange}
accept='image/*'
/>
</form.group>
Source: stackoverflow.com
Related Query
- how to make post request with image using axios?
- how do I make a post and get request with ReactJS, Axios and Mailchimp?
- How to POST request using axios with React Hooks?
- How to make a POST request using DJANGO REST framework with ajax
- How to use a custom React hook to make a POST or DELETE request with Axios
- How to make POST request with axios and React State Hook
- How To Make A Post Request Using Redux Thunk With Redux Toolkit
- How to send user data and its profile image using POST request from axios api to Django Rest Framework?
- how to make post request by axios with multiple parameters in Reactjs
- How to have config parameter in axios post request with headers required
- How to send image to server with Blob type using Axios in React Native?
- How to make a POST request with json content type with Semantic UI API
- How to make a post request using react redux?
- How to send array of object in post request using axios library
- How to make a loop request with React using Axios?
- How to make Post Request using ReactJS
- How to make a POST request using jquery?
- Upload Image with Axios Post request
- How do I make an axios request using a route parameter from React Router, then update state based on the response?
- React app testing, how to test an axios post request with Jest?
- 400 BAD REQUEST when POST using Axios in React with Nodejs/Express
- How to make an encoded POST request using axios?
- How to send data using fetch and POST request with credentials included?
- How do I mock a axios post request with Jest?
- make axios request using variable with the state set in a previous request
- How to connect put request with axios to make it work on frontend?
- how to convert an array to a array of objects with additional information in react using map when doing a POST api request
- how to post data in react es6 with axios using actions
- How to make a post request from array of object with Axios?
- how can i make a get request in axios to get the info of a user by clicking on his name using react.js
More Query from same tag
- Redirect react router with redux-saga
- Components mounting many times
- How to Pass an Event Handler as a prop in React?
- Creating dynamic forms and its validation react
- filter Graphql result by a Date variable
- Why canĀ“t you set the value of a destructured html element?
- React: Convert firebase url to file
- Upon clicking a button, how can I input the text from the button into an alert? (And how to disable and leave buttons selected)
- How would I go about stopping a decrement at 0 while using React useState hook?
- React SPA - GTM Analytics React-Helmet Previous Page Title
- Remove an element from an array of objects in react js
- ReactJS not compiles boostrap components. only returns HTML components. 0xerr011d
- Gatsby JS - gatsby-plugin-scroll-reveal not activating
- Copy scrollTop value from textarea to div
- Make children elements render only after parent element transition is over?
- Unhandled Rejection TypeError: Cannot read property 'id' of null
- Using .scss files as modules without naming them with .modules create-react-app
- Interactive Form for math
- React how to get item props from event.currentTarget
- How to get the home page item button conditionally styled in react?
- How can I change nested state in class component to state in functional component?
- React bootstrap overlaytrigger throwing a warning about unique key in iterator
- React, Graphql & Passport.js
- Set styling from parent component (props) and from component itself react native
- Updating state of a class inside a function in React
- Passing data between sibling components react hooks without context
- Dispatch to props only when clicked
- Reset options in <select> using React
- Django-Filters with class-based views: Apply Django FilterSet dynamically
- Apexcharts tooltip styles don't applied