Generic uploadFile

This commit is contained in:
Eduard Urbach 2018-03-03 00:20:10 +01:00
parent 5fad00dbe6
commit 7074fb86c3

View File

@ -10,7 +10,7 @@ export function selectFile(arn: AnimeNotifier, button: HTMLButtonElement) {
let file = input.files[0] let file = input.files[0]
previewImage(file, preview) previewImage(file, preview)
uploadImage(file) uploadFile(file, "/api/upload/avatar")
} }
input.click() input.click()
@ -32,12 +32,12 @@ function previewImage(file: File, preview: HTMLImageElement) {
} }
} }
// Upload image // Upload file
function uploadImage(file: File) { function uploadFile(file: File, endpoint: string) {
let reader = new FileReader() let reader = new FileReader()
reader.onloadend = async () => { reader.onloadend = async () => {
await fetch("/api/upload/avatar", { await fetch(endpoint, {
method: "POST", method: "POST",
credentials: "include", credentials: "include",
headers: { headers: {