'FormData not working on my react native project after update to expo SDK 45. I get [AxiosError: Network Error]
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.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
