From edca2a9bba61763fd56cf745f77c6b82d4619a18 Mon Sep 17 00:00:00 2001 From: King Wang Date: Wed, 9 Jun 2021 22:48:51 +0800 Subject: [PATCH] rem --- examples/file-upload/frontend/src/index.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/examples/file-upload/frontend/src/index.ts b/examples/file-upload/frontend/src/index.ts index 7ed60de..06058d4 100644 --- a/examples/file-upload/frontend/src/index.ts +++ b/examples/file-upload/frontend/src/index.ts @@ -7,18 +7,19 @@ let client = new HttpClient(serviceProto, { }); async function upload() { - // Load File - let file = document.querySelector('input[type=file]') as HTMLInputElement; - if (!file.files || !file.files[0]) { + let file = (document.querySelector('input[type=file]') as HTMLInputElement).files?.[0]; + if (!file) { alert('Please select a file') return; } - let fileData = await loadFile(file.files[0]); + + // Load file as Uint8Array + let fileData = await loadFile(file); // Upload let ret = await client.callApi('Upload', { fileData: fileData, - fileName: file.files[0].name + fileName: file.name }); // Error @@ -29,7 +30,6 @@ async function upload() { // Succ document.querySelector('ol')!.innerHTML += `
  • ${ret.res.url}
  • \n`; - file.value = ''; alert('Upload successfully!') }