How to download a file using ReactJS with Axios in the frontend and FastAPI in the backend?

In the Axios GET request, you have to make sure the responseType parameter is set to blob. Once you get the response from the API, you will need to pass the Blob object (i.e., response.data) to the URL.createObjectURL() function. Below is a fully working example on how to create and download a file (Document), using … Read more

FastAPI is not returning cookies to React frontend

First, dcreate the cookie, as shown in the example below (see this answer as well), and make sure there is no error returned when performing the Axios POST request, and that you get a ‘status’: ‘success’ response with 200 status code. from fastapi import FastAPI, Response app = FastAPI() @app.get(“https://stackoverflow.com/”) def main(response: Response): response.set_cookie(key=’token’, value=”some-token-value”, … Read more

How to use the axios library with AngularJS

How to use the axios library with AngularJS Bring its ES6 promises into the AngularJS context using $q.when: // axios example ̶a̶x̶i̶o̶s̶.̶g̶e̶t̶(̶u̶r̶l̶)̶.̶t̶h̶e̶n̶(̶(̶r̶e̶s̶p̶o̶n̶s̶e̶)̶ ̶=̶>̶ ̶{̶ $q.when(axios.get(url)).then((response) => { $scope.axiosResult = response.data; }); Only operations which are applied in the AngularJS execution context will benefit from AngularJS data-binding, exception handling, property watching, etc. Also use the $timeout … Read more

React Native – Axios – Trying to upload image

Can’t be sure but in my case I had to add a ‘name’ field to the file. Following other advices, I’ve end up with something like this: import axios from ‘axios’; import FormData from ‘form-data’; function upload (data, images, token) { const formData = new FormData(); formData.append(‘data’, data); images.forEach((image, i) => { formData.append(‘images’, { …image, … Read more

react native post form data with object and file in it using axios

when you are using react-native you don’t need “form-data” package. Because react native polyfills standard FormData api and exports it as global. second problem is axios converts form data automatically to string, so you need to use transformRequest config on request to override it. import { AxiosRequestConfig } from “axios”; const FormData = global.FormData; const … Read more