Skip to content

Instantly share code, notes, and snippets.

@zeroFruit
Created January 2, 2018 05:18
Show Gist options
  • Save zeroFruit/d46d4cae57e5e8cf59e1b541c0bf322e to your computer and use it in GitHub Desktop.
Save zeroFruit/d46d4cae57e5e8cf59e1b541c0bf322e to your computer and use it in GitHub Desktop.
react-native fetch form-data
import axios from 'axios';
const SERVER = 'https://...';
const requests = {
...
post: async (rootUrl, route = '', body = {}, config = {}) => {
const response = await axios.post(`${rootUrl}${route}`, body, config);
return getResponse(response);
}
};
const getResponse = ({ data, status }) => ({ data, status });
export const __insert = async (uri) => {
const formData = new FormData();
formData.append('photo', {
uri,
name: `sample.jpg`,
type: 'image/jpeg'
});
const { data } = await requests.post(SERVER, '/', formData);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment