showing results for - "return axios response from seperate file"
Myriam
14 Jun 2017
1var formData = new FormData();
2var imagefile = document.querySelector('#file');
3formData.append("image", imagefile.files[0]);
4axios.post('upload_file', formData, {
5    headers: {
6      'Content-Type': 'multipart/form-data'
7    }
8})
9
Luka
28 May 2018
1import axios from 'axios';
2
3export function getData(config, callback, errorcallback){
4    axios.get(url, config)
5    .then(res => {
6      //do something
7      if(callback != null){
8         callback(res);
9      }
10    })
11    .catch(err => {
12      // catch error
13      if(errorcallback != null){
14         errorcallback(err);
15      }
16    })
17}
18In any component, use as follows
19
20// get the location of your apicalls.js file and use to import like below
21import { getData } from '../../routetothisjsfile'
22
23
24//use it 
25var config = { "Access-Control-Allow-Origin": "*" }
26getData(config, (res) => {
27    //success
28},(err) => {
29    //error
30    alert(err);
31});
32
Jonas
21 Aug 2020
1import axios from 'axios';
2
3export const onAuthenticate = payload => {
4  const URL = `YOUR_URL`;
5  return axios(URL, {
6    method: 'POST/GET',
7    headers: {
8      'content-type': 'application/json', // whatever you want
9    },
10    data: payload,
11  })
12    .then(response => response.data)
13    .catch(error => {
14      throw error;
15    });
16};
17in you App.js
18
19import * as AuthenticateAPI from 'api/AuthenticationAPI';
20
21 // in your CDM
22 componentDidMount(){
23  AuthenticateAPI.onAuthenticate(payload).then((res)=>{ //any payload you want to send just for example
24    you can get response here in then block
25 }) 
26 }
queries leading to this page
js send image axiossend file as an attachment in api axiosaxios express file uploadhow to upload a file using axiosnodejs to file object to axios postfile upload with axiossend file and key in one request axiosnodejs axios upload image to orter serverupload an img using axiosnodejs axios post fileaxios send file and datahow to send file to server with axiosupload file using axios reacthow to send image with axiosupload an image with axiosuploading files with axiosaxios upload file nodejsaxios write txt fileuploading image with axiosread file from api axiosaxios load json filesend files from axios node jsaxios upload text fileupload a file to another server using axios in nodejssave a file axiossend file using axios node jssend file with axios reactaxios post download fileaxios body and fileshow to send a file to an api in axioshow to send file using axios in reactupload file with axiossend file with axiosaxios post fileshow to upload a file and a request body in axiosupload file using put method axiosaxios post json and file in one requesthow to pass file in axios body using axiospost file type axios jsoncreate file http in axiosaxios post object with file propertysend a file with axios expressaxios send post data with filesend axios with filehow to send text file using axios in nodejssend file in axios get nilaxios post file datasend file to server axios from 3a2019send file in json axiosaxios put fileaxios how to define in a single filehow to accept file data in axios postsend files with axiosget file from axiospost file from axios to nodejsaxios how to send file to php scriptsend files to req file axiosto file object nodejs axios postaxios post with file and bodyaxios post file with paramsupload images with axiosread file with axiosaxios post file listupload image axiosaxio post filesend file as json body axiosfile in axiossend text as a file axiosaxios get file from url and save according to file typeattach files to an axios requesthow to pass a file object in a get axios requesthow to upload file from axiosuse axios to upload a fileaxios text filejs upload files axiossend file axios nodejsreact axios post fileaxios send file nodejsread file using axiosattach files to an axios request nodeaxios post files and textopen file from axios requestsending file in axiosfile upload axiossending file with data object in axios requestaxios send file along with dataaxios file upload method postuploadfile with axiosaxios receive fileaxios data with fileaxios hit to get php fileaxois upload fileaxios file uploadaxios convert response to filehow to save axios response to file jsreact file upload with axiosupload image from application 2fjson axiossend file buffer from axiosaxios post with filessend file and data to server axiosaxios to run filesend file via axiosaxios options for uploading fileaxios request body when file uploadingobject file axiosaxios upload file s3axios posr fileaxios send file in bodyaxios send json filenode axios file uploadaxios send file postaxios send file as whole dataaxios add fileaxios send file and metadataget from axios and write file nodesending file axios postaxios upload file without save jsaxios get filepost a file with axiosaxios file postaxios send image dataupload file to gcs axios javascripthow to get file axiosaxios separate filehow to send a file of type json as a request in axiosaxios upload fi 3beaxios send post data with file from nodejs upload file using axiosaxios post to file to another api on serverupload image with axios nodejshow to send files from one api to another axiosaxios submit file how to send files to express using axiossending file with other sstring data in axios apiaxios write response to file posthow to create api axios in one filesend file with post axiosaxios post send file server side axios image uploadhow to upload images with axios 23710axios write fileaxios pas fileaxios upload imageaxios send fileaxios upload file with backendsending file to server with axiosreturn axios response from seperate fileaxios response filesent file via axiospassing file from client to server axiosaxios upload fileaxios get a file axios form json how to send fileaxios put filesfhow to send file over a post request with axiosaxios send file reactaxios write response to fileaxios send image filepost file axiosaxios send file and data reactsetting axios request in one filehow get file in axiosaxios send a fileaxios download response fileaxios download file responseaxios send input filehow to get file from input in javascript and send it to axios requestreact axios post request with file uploadsend file in body axioshow to add file to http request with axiossave file axiosaxios send file as form datasendig a file over axiosadd files to request axiosaxios request send omage filehow to send a file through axios requetsaxios put request file datasend req files axioshow to send files to an api in axiossend file using axiosupload file axiosaxios send json and fileaxios file uaxios how to send file in formaxios post fileupload file using put method axios from nodejsaxios send file bufferaxios get from local filereturn axios response from seperate file