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]
previewImage(file, preview)
uploadImage(file)
uploadFile(file, "/api/upload/avatar")
}
input.click()
@ -32,12 +32,12 @@ function previewImage(file: File, preview: HTMLImageElement) {
}
}
// Upload image
function uploadImage(file: File) {
// Upload file
function uploadFile(file: File, endpoint: string) {
let reader = new FileReader()
reader.onloadend = async () => {
await fetch("/api/upload/avatar", {
await fetch(endpoint, {
method: "POST",
credentials: "include",
headers: {