[user] Fixed avatar upload

This commit is contained in:
Ferdinand Thiessen 2021-04-01 03:16:56 +02:00
parent 7d914d065e
commit fc35e2ecec
2 changed files with 11 additions and 9 deletions

View File

@ -135,7 +135,7 @@ export default defineComponent({
const password = ref('');
const newPassword = ref('');
const avatar = ref<string[]>([]);
const avatar = ref<File | FileList | string[]>();
const userModel = ref(props.user);
const canSetRoles = computed(() => hasPermission('users_set_roles'));
@ -157,7 +157,7 @@ export default defineComponent({
progress: true,
actions: [{ icon: 'mdi-close', color: 'white' }],
});
avatar.value = [];
avatar.value = undefined;
}
function save() {
@ -174,12 +174,14 @@ export default defineComponent({
emit('update:user', changed);
if (avatar.value && (avatar.value.length > 0 || avatar.value instanceof File))
userStore.uploadAvatar(changed, avatar.value[0]).catch((response: Response) => {
if (response && response.status == 400) {
onAvatarRejected();
}
});
if (avatar.value)
userStore
.uploadAvatar(changed, avatar.value instanceof File ? avatar.value : avatar.value[0])
.catch((response: Response) => {
if (response && response.status == 400) {
onAvatarRejected();
}
});
reset();
}

View File

@ -64,7 +64,7 @@ export const useUserStore = defineStore({
return data;
},
async uploadAvatar(user: FG.User, file: string) {
async uploadAvatar(user: FG.User, file: string | File) {
const formData = new FormData();
formData.append('file', file);
await api.post(`/users/${user.userid}/avatar`, formData, {