axios

how to get onUploadProgress in axios?

↘锁芯ラ 提交于 2019-11-28 20:51:35
I am little bit confused that how to upload progress evt with axios.Actually I am storing huge number files into aws s3.For that how to get uploaded progress I need this function onUploadProgress Currently my Post request is like this export function uploadtoCdnAndSaveToDb(data) { return dispatch => { dispatch(showUnderLoader(true)); return axios.post('/posttodb',{data:data}, ).then((response) => { console.log(response.data) }) } } christopher The Axios repository has a clear example on how to do this: https://github.com/mzabriskie/axios/blob/master/examples/upload/index.html Excerpt from the

Axios Interceptors retry original request and access original promise

一个人想着一个人 提交于 2019-11-28 18:24:52
I have an interceptor in place to catch 401 errors if the access token expires. If it expires it tries the refresh token to get a new access token. If any other calls are made during this time they are queued until the access token is validated. This is all working very well. However when processing the queue using Axios(originalRequest) the originally attached promises are not being called. See below for an example. Working interceptor code: Axios.interceptors.response.use( response => response, (error) => { const status = error.response ? error.response.status : null const originalRequest =

Force download GET request using axios

别来无恙 提交于 2019-11-28 17:02:44
I'm using vuejs 2 + axios. I need to send a get request, pass some params to server, and get a PDF as a response. Server uses Laravel. So axios.get(`order-results/${id}/export-pdf`, { params: { ... }}) makes successful request but it does not start force downloading, even though server returns correct headers. I think this is a typical situation when you need to, say, form a PDF report and pass some filters to server. So how could it be accomplished? Update So actually I found a solution. However the same approach didn't work with axios, don't know why, that's why I used raw XHR object. So the

Image returned from REST API always displays broken

和自甴很熟 提交于 2019-11-28 14:34:16
I am building a content management system for an art portfolio app, with React. The client will POST to the API which uses Mongoose to insert into a MongoDB. The API then queries the DB for the newly inserted image, and returns it to the client. Here's my code to connect to MongoDB using Mongoose: mongoose.connect('mongodb://localhost/test').then(() => console.log('connected to db')).catch(err => console.log(err)) mongoose.Promise = global.Promise const db = mongoose.connection db.on('error', console.error.bind(console, 'MongoDB connection error:')) const Schema = mongoose.Schema; const

Axios request giving getter setter methods instead of data queried

走远了吗. 提交于 2019-11-28 14:13:25
I'm working with Laravel and Vue to make a single page web application. I've used Vue before to get the data from a database using a controller with no problem, but for some reason I'm now only getting a seemingly infinitely nested JS object that has getter and setter methods stored in each parent object instead of the data I queried. I've seen other people with similar issues, but the solutions that worked for them didn't work for me. For example, some people used JSON.parse(JSON.stringify(response.data)); to get just the raw data, but this doesn't work when I attempt to store it in this

How to prevent Axios from encoding my request parameters?

拈花ヽ惹草 提交于 2019-11-28 10:58:46
I'm trying to pass in an API key through the URL parameters in my GET request. However, I notice that Axios encodes the characters in my API key when sending the request. This causes the API to reject my request as it couldn't recognise my key. How can I prevent Axios from encoding my GET parameters? You can use a custom param serializer as follows: axios.get('https://foobar.com/api', { paramsSerializer: function(params) { var result = ''; // Build the query string return result; } }); paramsSerializer can be set at the instance level: var instance = axios.create({ paramsSerializer: function

Setting authorization header in axios

喜欢而已 提交于 2019-11-28 08:11:35
问题 I have been trying to make a GET request to the National Park Service API with axios and have tried several ways to set my API key in the request header to no avail. Any assistance will be greatly appreciated. I have tried: axios.defaults.headers.common['Authorization'] = "MY-API-KEY"; axios.get('https://developer.nps.gov/api/v0/parks?parkCode=yell') .then((resp) => { console.dir(resp); }); and let config = {'Authorization': 'MY-API-KEY'}; axios.get('https://developer.nps.gov/api/v0/parks

Has been blocked by CORS policy: Response to preflight request doesn’t pass access control check

点点圈 提交于 2019-11-28 07:00:14
问题 I have created trip server. It works fine and we are able to make POST request by Insomnia but when we make POST request by axios on our front-end, it sends an error: has been blocked by CORS policy: Response to preflight request doesn’t pass access control check: It does not have HTTP ok status. Our request on axios: let config = { headers: { "Content-Type": "application/json", 'Access-Control-Allow-Origin': '*', } } let data = { "id": 4 } axios.post('http://196.121.147.69:9777/twirp/route

GraphQL returning null data from axios [duplicate]

萝らか妹 提交于 2019-11-28 06:41:48
问题 This question already has an answer here: Why does a GraphQL query return null? 1 answer I am writing a GraphQL server in Node.js and Express. I have a JSON file of data and so I am using Axios to query data from that JSON file and pass it to GraphQL query, const RootQuery = new GraphQLObjectType({ name:'RootQueryType', fields: { holiday: { type: Holiday, args:{ date:{type:GraphQLString}, }, resolve(parentValue, args) { return axios.get('http://localhost:3000/holidays?date='+ args.date).then

Waiting for all promises called in a loop to finish

孤人 提交于 2019-11-28 06:01:16
I'm using the axios promise library, but my question applies more generally I think. Right now I'm looping over some data and making a single REST call per iteration. As each call completes I need to add the return value to an object. At a high level, it looks like this: var mainObject = {}; myArrayOfData.forEach(function(singleElement){ myUrl = singleElement.webAddress; axios.get(myUrl) .then(function(response) { mainObject[response.identifier] = response.value; }); }); console.log(convertToStringValue(mainObject)); What's happening of course is when I call console.log the mainObject doesn't