iOS Safari 13.3.1 上传文件大小为0

b00*_*ter 4 safari upload file-upload form-data jquery-file-upload

我在 PHP 上有一个简单的页面站点,用户可以在其中上传文件(stl-model)。起初我是用来上传 JS 的FormData。它适用于 Chrome 和 Firefox,但 Safari iOS 有时会发送大小为 0 字节的文件。JS console.log 显示,发送前文件大小为 718120 字节。PHP 调试模式显示全局$ _FILE存在且文件名为真,但文件为空:

(
    [name] => TRRSExtenderMount.stl
    [type] => application / octet-stream
    [tmp_name] => / tmp / phphDceFc
    [error] => 0
    [size] => 0
)
Run Code Online (Sandbox Code Playgroud)

大小为 0 的错误不时重复。

我试过的:

  • 检查 phpinfo post_max_size, upload_max_filesize
  • 在不同的设备上测试(全部使用 13.3.1 iOS)
  • 使用不同的 stl 文件和文件大小(从 0.5mb 到 16mb)进行测试
  • 使用 3g、4g 和 wi-fi 进行测试
  • 检查上传速度慢:检查文件大小,等待10秒再检查
  • 使用没有 JS 的 POST 方法更改了标准 HTML 的输入表单

但错误再次重复。我究竟做错了什么?

b00*_*ter 5

所以,我解决了这个问题。也许我的经验可以帮助某人:

  1. 如果您不重新加载页面,则在第一次调用 2 分钟后重复 Ajax 调用时,我重现了该错误返回。
  2. 我注意到文件对象属性“lastModified”总是等于文件创建日期。因此浏览器可能会使用缓存中的 Formdata。我添加了下一个代码以始终发送“新”文件:
    this.trueFile = new File([this.originalFile], 'file-name.stl', {lastModified: new Date()});
Run Code Online (Sandbox Code Playgroud)
  1. 之后错误发生了变化:第二次 Ajax 调用(2 分钟后)在超时时崩溃并返回下一条消息:
    TypeError: 'caller', 'callee', and 'arguments' properties may not be accessed on strict mode
Run Code Online (Sandbox Code Playgroud)
  1. 下一步我发现了这个问题:Getting TypeError: 'caller', 'callee', and 'arguments' properties may not be accessed on strict mode,并删除下一行: dataType: 'json'从我的代码中。它有帮助。