send auth with image upload request

This commit is contained in:
Bart Akeley 2018-02-25 12:38:34 -06:00
parent 845c227fc8
commit 8eeed01a07
2 changed files with 14 additions and 3 deletions

View file

@ -33,3 +33,13 @@ export const fetchRequest = async ({
return res.json();
};
export const fetchRequestBinary = async ({ endpoint, body }: { endpoint: string, body: any }) => {
return fetch(`http://${BASE_URL}${endpoint}`, {
method: 'POST',
headers: {
...AuthManager.getAuthHeader(),
},
body,
});
};

View file

@ -2,9 +2,10 @@
import { memoize } from 'ramda';
import FilterRecord from '../records/FilterRecord';
import FoodItemRecord from '../records/FoodItemRecord';
import { fetchRequest } from './FetchApi';
import { fetchRequest, fetchRequestBinary } from './FetchApi';
import ImageResizer from 'react-native-image-resizer';
import { BASE_URL } from '../constants/AppConstants';
import AuthManager from '../AuthManager';
const IMAGE_HEIGHT = 600;
const IMAGE_WIDTH = 800;
@ -100,8 +101,8 @@ export const addImage = async ({
name: 'photo.png',
});
return fetch(`http://${BASE_URL}/addimage/${foodItemId}`, {
method: 'POST',
return fetchRequestBinary({
endpoint: `/addimage/${foodItemId}`,
body,
});
};