hejianhao
2026-01-26 0fa4c73654615b01d645b1cf3034fd1f3618aa1c
fix: 改进上传文件类型的检测逻辑

通过添加对远程文件 Content-Type 的检查,更准确地判断视频文件,避免仅依赖文件扩展名或本地类型导致的误判。
1个文件已修改
19 ■■■■■ 已修改文件
estate-frontend-v2024/src/views/screenSetting/forms/edit-projectProgress-form.jsx 19 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
estate-frontend-v2024/src/views/screenSetting/forms/edit-projectProgress-form.jsx
@@ -33,7 +33,6 @@
  }
  viewWillAppear() {
    // Reset form to ensure no stale data from previous edits
    this.props.form.resetFields();
    const { editableData } = this.state;
@@ -166,7 +165,6 @@
        const responsePayload = { finalName, ...res.data };
        data.onSuccess(responsePayload, data.file);
        // Note: handleUploadChange will trigger after this via onChange
      } else {
        message.error("上传失败");
        data.onError();
@@ -185,11 +183,9 @@
    if (!url && file.response && file.response.finalName) {
      url = this.getPreviewUrl(file.response.finalName);
    }
    // Fallback for old logic or direct string
    if (!url && file.response && file.response.data && typeof file.response.data.data === 'string') {
      url = this.getPreviewUrl(file.response.data.data);
    }
    // If we still don't have a url (e.g. file.originFileObj), we can read it.
    if (!url && file.originFileObj) {
      url = await new Promise((resolve) => {
        const reader = new FileReader();
@@ -198,8 +194,19 @@
      });
    }
    // Determine type
    const isVideo = (url && url.match(/\.(mp4|webm|ogg)$/i)) || (file.type && file.type.startsWith('video/'));
    let isVideo = (url && url.match(/\.(mp4|webm|ogg)$/i)) || (file.type && file.type.startsWith('video/'));
    if (!isVideo && url && !url.startsWith('data:')) {
      try {
        const res = await fetch(url, { method: 'GET' });
        const contentType = res.headers.get('Content-Type');
        if (contentType && contentType.startsWith('video/')) {
          isVideo = true;
        }
      } catch (e) {
        console.warn('Check file type failed', e);
      }
    }
    this.setState({
      previewUrl: url,