Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS Safari 13.3.1 uploaded file size is 0

I have simple-page site on PHP, where users can upload file (stl-model). At first I was use for upload JS FormData. It's work in Chrome and Firefox, but Safari iOS sometimes send file with size = 0 bytes. JS console.log show, that file size 718120 bytes before send. PHP debug mode show that global $ _FILE exists and file name is true, but file is empty:

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

The error with size 0 repeats from time to time.

What I tried:

  • checked phpinfo post_max_size, upload_max_filesize
  • tested on different devices (all with 13.3.1 iOS)
  • tested with different stl-files and file-size (from 0.5mb to 16mb)
  • tested with 3g, 4g and wi-fi
  • checked slow upload speed: check file size, wait 10 seconds and check it again
  • changed input form for standart HTML with POST method without JS

But the error was repeated again. What am I doing wrong?

like image 880
b00ter Avatar asked Mar 02 '23 16:03

b00ter


1 Answers

So, I fixed this problem. May be my experience can help somebody:

  1. I reproduced that error returns when you repeat Ajax call 2 min later that first call if you don't reload page.
  2. I noticed File object attribute "lastModified" always equal to file creation date. So browser may be used Formdata from cache. I added next code to always send "new" file:
    this.trueFile = new File([this.originalFile], 'file-name.stl', {lastModified: new Date()});
  1. After that the error changed: second Ajax call (after 2 min) crashed on timeout and returned next message:
    TypeError: 'caller', 'callee', and 'arguments' properties may not be accessed on strict mode
  1. Next step I found this question: Getting TypeError: 'caller', 'callee', and 'arguments' properties may not be accessed on strict mode , And delete next row: dataType: 'json' from my code. And it helped.
like image 125
b00ter Avatar answered Mar 23 '23 11:03

b00ter