ソースを参照

chore(uploader): edit web method put upload type

richard1015 3 年 前
コミット
df0fd5adc9

+ 3 - 0
src/packages/__VUE/uploader/index.vue

@@ -185,6 +185,9 @@ export default create({
       uploadOption.xhrState = props.xhrState as number;
       uploadOption.xhrState = props.xhrState as number;
       uploadOption.headers = props.headers;
       uploadOption.headers = props.headers;
       uploadOption.withCredentials = props.withCredentials;
       uploadOption.withCredentials = props.withCredentials;
+      try {
+        uploadOption.sourceFile = fileItem.formData.get(props.name);
+      } catch (error) {}
       uploadOption.onStart = (option: UploadOptions) => {
       uploadOption.onStart = (option: UploadOptions) => {
         fileItem.status = 'ready';
         fileItem.status = 'ready';
         fileItem.message = translate('readyUpload');
         fileItem.message = translate('readyUpload');

+ 6 - 1
src/packages/__VUE/uploader/uploader.ts

@@ -3,6 +3,7 @@ export class UploadOptions {
   name = 'file';
   name = 'file';
   fileType? = 'image';
   fileType? = 'image';
   formData?: FormData;
   formData?: FormData;
+  sourceFile: any;
   method = 'post';
   method = 'post';
   xhrState = 200;
   xhrState = 200;
   timeout = 30 * 1000;
   timeout = 30 * 1000;
@@ -47,7 +48,11 @@ export class Uploader {
         xhr.setRequestHeader(key, value as string);
         xhr.setRequestHeader(key, value as string);
       }
       }
       options.onStart?.(options);
       options.onStart?.(options);
-      xhr.send(options.formData);
+      if (options.method.toLowerCase() == 'put') {
+        xhr.send(options.sourceFile);
+      } else {
+        xhr.send(options.formData);
+      }
     } else {
     } else {
       console.warn('浏览器不支持 XMLHttpRequest');
       console.warn('浏览器不支持 XMLHttpRequest');
     }
     }