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.