From d9a917176ae5ee96465bc57daf9a66a222cca174 Mon Sep 17 00:00:00 2001 From: sigoden Date: Sat, 28 May 2022 20:40:49 +0800 Subject: [PATCH] fix: cannot upload in root --- src/index.html | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/index.html b/src/index.html index 592b811..e330dbc 100644 --- a/src/index.html +++ b/src/index.html @@ -45,20 +45,21 @@ class Uploader { idx = 0; file; - path; $elem; constructor(idx, file) { this.idx = idx; this.file = file; - this.path = location.pathname + "/" + file.name; } upload() { - const { file, idx, path } = this; + const { file, idx } = this; + let url = location.href.split('?')[0]; + if (!url.endsWith("/")) url += "/"; + url += encodeURI(file.name); $uploaders.insertAdjacentHTML("beforeend", `
- ${file.name} (0%) + ${file.name} (0%)
`); this.$elem = document.getElementById(`file${idx}`); @@ -67,7 +68,7 @@ ajax.addEventListener("load", e => this.complete(e), false); ajax.addEventListener("error", e => this.fail(e), false); ajax.addEventListener("abort", e => this.fail(e), false); - ajax.open("PUT", path); + ajax.open("PUT", url); ajax.send(file); }