小小盗草人 2021-09-17 08:46 采纳率: 0%
浏览 72
已结题

FormData文件上传响应302和200

这里使用 new window.FormData() 方式,代码也是考的同事的,他那边不限制文件类型,我使用的时候对一些jar exe等文件类型就不支持,目前自己试出来一些常见的格式,先做的上传文件类型限制,但还是想解决一下;问题具体表现为http响应302和一个200的,可以看截图:
这是我的上传文件的js:

            //附件上传   
            attachFileChange: function() {
            const fileTypes = "doc,docx,xls,xlsx,pdf,ppt,pptx,txt,jpg,jpeg,png,bmp,gif,zip,rar";
            const fileTypeArray = fileTypes.split(",");

            const attachFile = $("#attachFile").get(0).files[0];
            /*
            const filePathArray = attachFile.name.toLowerCase().split('.');
            const fileType = filePathArray[filePathArray.length - 1];
             if (_.indexOf(fileTypeArray, fileType) == -1) {
               HyMessage({
                 message: `支持的附件格式【${fileTypes}】,当前格式:${fileType}。`,
                 type: 'warning'
               });
              return;
            }
            */

            const me = this;
            const formData = new window.FormData();
            formData.append("file", attachFile);
      
            $.ajax({
              type: "POST",
              data: formData,
              contentType: false,
              processData: false,
              url: $$pageContextPath+'dynamics/uploadDynamicsAttachFile?t='+new Date().getTime(),
              success: response => {
                 //xxxxxx
              },
            });

上传成功:

img

上传失败会响应两个(302+200):

img

响应的302:

img

响应的200:

img

自己排查错误nginx是没有问题的,去掉nginx也测过,百度也无果。
  • 写回答

1条回答 默认 最新

  • 普通网友 2021-09-17 08:50
    关注

    你响应302的那个链接,你去除下时间戳试试;

    估计是被nginx给缓存了

    评论

报告相同问题?

问题事件

  • 已结题 (查看结题原因) 9月18日
  • 修改了问题 9月17日
  • 修改了问题 9月17日
  • 修改了问题 9月17日
  • 展开全部

悬赏问题

  • ¥15 在获取boss直聘的聊天的时候只能获取到前40条聊天数据
  • ¥20 关于URL获取的参数,无法执行二选一查询
  • ¥15 液位控制,当液位超过高限时常开触点59闭合,直到液位低于低限时,断开
  • ¥15 marlin编译错误,如何解决?
  • ¥15 有偿四位数,节约算法和扫描算法
  • ¥15 VUE项目怎么运行,系统打不开
  • ¥50 pointpillars等目标检测算法怎么融合注意力机制
  • ¥20 Vs code Mac系统 PHP Debug调试环境配置
  • ¥60 大一项目课,微信小程序
  • ¥15 求视频摘要youtube和ovp数据集