From acaad4f21703db018ec6cedc9f20b56900a5a13f Mon Sep 17 00:00:00 2001 From: xjh22222228 Date: Sun, 21 Mar 2021 15:56:18 +0800 Subject: [PATCH] fix: upload file name --- src/components/create-web/index.component.ts | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/components/create-web/index.component.ts b/src/components/create-web/index.component.ts index 6309033..12fcf08 100644 --- a/src/components/create-web/index.component.ts +++ b/src/components/create-web/index.component.ts @@ -111,32 +111,30 @@ export class CreateWebComponent implements OnInit { handlePasteImage = event => { const items = event.clipboardData?.items let file = null - let suffix = '' if (items.length) { for (let i = 0; i < items.length; i++) { if (items[i].type.startsWith('image')) { file = items[i].getAsFile() - suffix = file.type.split('/').pop() break; } } } if (file) { - this.handleUploadImage(file, suffix) + this.handleUploadImage(file) } } - handleUploadImage(file: Blob, suffix: string) { + handleUploadImage(file: File) { const that = this const fileReader = new FileReader() fileReader.readAsDataURL(file) fileReader.onload = function() { that.uploading = true that.iconUrl = this.result as string - const url = (this.result as string).split(',')[1] - const path = `nav-${Date.now()}.${suffix}` + const url = that.iconUrl.split(',')[1] + const path = `nav-${Date.now()}-${file.name}` createFile({ branch: 'image', @@ -162,12 +160,11 @@ export class CreateWebComponent implements OnInit { const { files } = e.target if (files.length <= 0) return; const file = files[0] - const suffix = file.type.split('/').pop() if (!file.type.startsWith('image')) { return this.message.error('请不要上传非法图片') } - this.handleUploadImage(file, suffix) + this.handleUploadImage(file) } handleCancel() { -- GitLab