axios

Get image from server and preview it on client

只谈情不闲聊 提交于 2019-12-06 03:25:55
So i'm trying to get an image from a server and previewing it on the client, i can retrieve the image for now, but i don't know how to preview it on a web page asynchronously. axios.get(link,{responseType:'stream'}).then(img=>{ // What i have to do here ? }); Thank you. First, you need to fetch your image with the response type arraybuffer . Then you can convert the result to a base64 string and assign it as src of an image tag. Here is a small example with React. import React, { Component } from 'react'; import axios from 'axios'; class Image extends Component { state = { source: null };

react.js using axios to post data to php, but php echo empty

家住魔仙堡 提交于 2019-12-06 02:29:37
问题 I am using react.js, axios, and PHP to post data to MySQL database This is my react.js code sendData(){ var data = new FormData(); data.append('name', 'jessie'); data.append('time', '12:00'); data.append('food', 'milk'); data.append('nutrition', 'vitaminA'); axios.post( './sendData.php',{ data: data }) .then(response => { console.log(response) console.log(response.data) this.filter = response.data }) .catch(e => { this.errors.push(e) }) } And this is my PHP code <?php $servername = "127.0.0.1

run response interceptor only once when multiple API calls

一个人想着一个人 提交于 2019-12-06 02:05:38
问题 I have an interceptor like this axios.interceptors.response.use(undefined, err=> { const error = err.response; console.log(error); if (error.status===401 && error.config && !error.config.__isRetryRequest) { return axios.post(Config.oauthUrl + '/token', 'grant_type=refresh_token&refresh_token='+refreshToken, { headers: { 'Authorization': 'Basic ' + btoa(Config.clientId + ':' + Config.clientSecret), 'Content-Type': 'application/x-www-form-urlencoded,charset=UTF-8' } }) .then(response => {

Axios request interceptor not working

妖精的绣舞 提交于 2019-12-06 01:45:42
问题 I'm trying to make axios working with a request interceptor. However before a request is made the interceptor is not triggered. What could be going wrong here? I've red already a lot about this problem but not found a solution so far. Could use some help here! This is my code: import VueRouter from 'vue-router'; import Login from './components/Login.vue' import Home from './components/Home.vue' import axios from 'axios'; window.Vue = require('vue'); window.axios = axios.create({ baseURL:

Send “raw” payload to Axios

久未见 提交于 2019-12-05 21:24:12
问题 How can I send a raw payload/request body to Axios? The endpoint I'm trying to call expects the request body to just be a string which it'll scoop up and use. If I try to just pass a string to axios.post() for the requestBody , it'll convert it to an object with no value ( { "this+is+my+message": "" } ) and ends up getting parsed like this "this+is+my+message=" . I checked the documentation, but couldn't find any option that seemed to work. transformRequest seemed to be the most obvious, but

Axios and twitter API

我的未来我决定 提交于 2019-12-05 20:36:18
I'm having an issue with axios and twitter API. I made successful request using Postman (with Authorization header set - OAuth 1.0). Now I'm trying to do the same and all I get is: Failed to load https://api.twitter.com/1.1/lists/statuses.json: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:3000' is therefore not allowed access. The response had HTTP status code 400. I also see in the Network chrome tab, that only the OPTIONS is being sent. This is how my axios configuration

AXIOS: how to run http requests concurrently and get the result of all requests event if a request fails

醉酒当歌 提交于 2019-12-05 18:48:05
I am trying to make server get requests concurrently, in order to do that I have written the following function. Problem If a single call is failing then I am not able to get the response of rest of the requests. export const getAll = async (collection) => { return new Promise((resolve, reject) => { const requests = collection.map(req => { const config = { headers: req.headers, params: req.params } return axios.get(req.url, config); }) axios.all(requests) .then(axios.spread((...args) => { // all succerss resolve(args); })) .catch(function (error) { // single call fails and all calls are lost

Axios - How to read JSON response?

允我心安 提交于 2019-12-05 14:43:18
问题 Axios 0.17.1 .then(function (response) { console.log(response); //console.log(response.status); //It is an error -> SyntaxError: Unexpected token u in JSON at position 0 console.log(JSON.parse(response.data.error)); console.log(response.data.error); //undefined. The console.log of response is {data: "{"error":"Name must be entered with more than one … NULL↵ ["isPipe":protected]=>↵ NULL↵ }↵}↵", status: 203, statusText: "Non-Authoritative Information", headers: {…}, config: {…}, …} config :

Download binary file with Axios

假如想象 提交于 2019-12-05 14:12:41
For example, downloading of PDF file: axios.get('/file.pdf', { responseType: 'arraybuffer', headers: { 'Accept': 'application/pdf' } }).then(response => { const blob = new Blob([response.data], { type: 'application/pdf', }); FileSaver.saveAs(blob, 'file.pdf'); }); The contend of downloaded file is: [object Object] What is wrong here? Why binary data not saving to file? I was able to create a workable gist (without using FileSaver) as below: axios.get("http://my-server:8080/reports/my-sample-report/", { responseType: 'arraybuffer', headers: { 'Content-Type': 'application/json', 'Accept':