Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6287

FormData not working on my react native project after update to expo SDK 45. I get [AxiosError: Network Error]

$
0
0

So this is my function using saga:

function* handleAvatarUpdate({ payload }: UpdateAvatarRequest) {  const localAvatarUri = payload;  try {    if (!localAvatarUri) return;    const fileType = localAvatarUri.substring(      localAvatarUri.lastIndexOf('.') + 1,    );    const data = new FormData();    data.append('avatar',      JSON.parse(        JSON.stringify({          uri: localAvatarUri,          type: `image/${fileType}`,          name: `photo.${fileType}`,        }),      ),    );    yield put(updateAvatarLoading(true));    const response: AxiosResponse<IUser> = yield call(      api.patch,'/users/avatar',      data,    );    yield call(StoreUser, response.data);    yield put(updateAvatarLoading(false));    yield put(updateAvatarSuccess(response.data.avatar));  } catch (err) {    yield put(updateAvatarLoading(false));    yield put(updateAvatarFailure());  }}

As you can see I use FormData to update the user profile picture on my nodejs backend. If I try to update the username it works. But if try to update the user profile picture, using FormData, I get [AxiosError: Network Error] and the status code from the error is 0.


Viewing all articles
Browse latest Browse all 6287

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>