21

SOLVED/NOTE: I have accepted the answer of adding the "accept=" option to the HTML code as a solution to the problem. It should be noted that although this does work as as a work around, the root cause is likely a Safari bug - it should NOT be a requirement to add this to your HTML to make this functionality work.

ORIGINAL PROBLEM DESCRIPTION & INFO:

My mac received an update this morning, now running macOS Mojave 10.14.6 (18G6042). It looks like Safari must have received an update as part of this, although Apple didn't give the update specifics, just the usual "You need to Restart" with no extra info, followed by 20 mins of waiting. Safari is now Version 14.0.1 (14610.2.11.51.10).

Since the update, I find that I can no longer submit files through HTML forms in Safari. The "Choose File" button is displayed, but clicking it results in nothing. I'll post my code below, but I also verified this using the w3schools example at https://www.w3schools.com/tags/att_input_type_file.asp (it won't work in Safari now either), and my code works fine in Chrome & Firefox on the same laptop.

Does anyone have any info on this? Are extra directives required for this to work in Safari now? Is it blocked due to some security issue? Is this just a bug?

Here's my test code in case it is relevant, although it's more or less the same as the w3schools example, with some added PHP to display the file info.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional/EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="UTF-8">
<meta http-equiv="Content-type" content="text/html; charset=UTF-8">
<title>Upload File Test</title>
</head>

<body>

<br/>
<?php
  if (isset($_POST["UploadFile"]))
  {
      if ($_FILES["myfile"]["error"] > 0)
      {
        echo "No file was selected.<br/>\n";
      }
      else
      {
          echo "Upload: " . $_FILES["myfile"]["name"] . "<br/>\n";
          echo "Type: " . $_FILES["myfile"]["type"] . "<br/>\n";
          echo "Size: " . ($_FILES["myfile"]["size"] / 1024) . " kB<br/>\n";
          echo "Stored in: " . $_FILES["myfile"]["tmp_name"] . "<br/>\n";
      }
  }
?>

<FORM NAME="file_upload" METHOD="POST" ACTION="file-test.php" enctype="multipart/form-data" accept-charset="UTF-8">

<label for="file">Upload File:</label>
<input type="file" name="myfile" id="myfile" />

<INPUT type="Submit" name="UploadFile" value="Upload" />
         
</FORM>

<br/>

</body>
</html>

MORE INFO: So the problem continues, and sometimes the dialog opens now, but sometimes it doesn't. Previously, the dialog would always open in the last directory you loaded or saved files from, I just saved a bunch of pages as PDF (via Print) for some work, and now when I go to Choose File again, it shows the dialog below (unfortunately the screenshot doesn't capture the full path, but you get the idea). So it looks like this is an issue within Safari, but I'm still not sure exactly what or how to rectify it. Plus, while the dialog opens on my local test page, it's not opening for web based pages (my sites, w3schools, etc).

Default Choose File Directory

MORE INFO: Safari just defaulted again to the "inaccessible" directory it keeps defaulting to sometimes, here's a screen shot, in case the additional info helps anyone further (probably just the guys at Apple in fixing the bug I'm guessing)... Normally you can't browse to this folder from Safari, which I'm guessing is part of this bug - Safari is trying to default to this directory for file upload, when it can't jump to the last previously used directory for whatever reason.

enter image description here

9
  • 1
    The functionality has curiously started working again, with no changes or restart. I wondered if the problem was permissions/security - Safari trying to open the file select dialog in a location with a permissions issue, and failing due to that. Who knows - when it did open I appeared to be in a Safari temp files folder location (I should have noted the exact folder), and I can now browse to other locations, and the function works fine. So apparently not any issue with the HTML, but some internal Safari and/or security issue. Nov 16, 2020 at 9:33
  • FYI, I'm getting reports of this from my users, too. But I just updated to Safari 14.0.1 and it works normally for me so far.
    – arlomedia
    Nov 18, 2020 at 19:40
  • 2
    I'm still see the issue with Safari 14.0.2 on Mojave Dec 26, 2020 at 12:55
  • I have the same issue on Mojave + Safari 14.0.1 - adding the accept attribute did nothing. Also doesn't work for my coworker on Big Sur + Safari 14.0.1 But on Big Sur the example from w3schools worked but not our own uploader which uses blueimp/jquery-file-upload so there is also some fragility there There's a thread on this issue on the apple forum: discussions.apple.com/thread/252045057
    – hejsan
    Jan 12, 2021 at 13:20
  • @hejsan - after you add the "accept" attribute to your code, make sure your browser is picking up the updated page, and not any cached version. I had the similar issues with inconsistencies when testing this originally, and found even a forced refresh wasn't necessarily giving me the new page sometimes - quit and restart Safari entirely to be sure when running any tests like this. Jan 26, 2021 at 10:51

6 Answers 6

13

I have run into the same issue yesterday.

Having looking into it I have found it working elsewhere and fixed it on the site I'm working on by adding an accept attribute with a file types list to the input tag. (e.g. <input type="file" accept=".xls,.xlsx,.xlsb,.txt,.csv,.tsv"/>)

Works fine now in Safari version 14.0.1 (14610.2.11.51.10) on Mojave 10.14.6

5
  • I agree, adding the "accept" option to the code does appear to rectify the issue, at least most of the time from tests I've done in the last couple of days. I'm not 100% sure this is the only factor, but it is certainly worth a try. Either way, I'm fairly certain at this point that the root cause issue is a Safari bug, and not an issue with the validity of anyone's HTML code. Nov 19, 2020 at 13:57
  • Indeed, this addition works for me too, congratulations for finding this!
    – PhiM
    Nov 20, 2020 at 7:42
  • Thank you for this solution! Adding an accept attribute to my input field has behavior restored.
    – whalesalad
    Nov 20, 2020 at 16:14
  • I added accept="*/*" but it failed to make a difference. Nov 25, 2020 at 15:33
  • I find that with or without an accept attribute, once Safari somehow gets into the "I will not respond to input type=file events" state, it stays that way across at least every page on my domain. So far only a reboot has been able to fix it.
    – DWR
    Feb 11, 2021 at 15:14
5

I confirm that this is a problem with Safari at least on Mojave. I have Safari 14.0.1 (14610.2.11.51.10) on Mojave 10.14.6 (18G6032 then 18G6042 after security update 2020-06: no change). It seems that no file upload will work: it fails on my own website with very simple html almost limited to <input type="file" />, and also fails on two standard CMS (an old WordPress and current MODX). There is no file selection window coming at all. I tried allowing anything (e.g. popup windows) : no change.

OS X's log indicates that Safari is denied file access when the button is clicked:

Sandbox: Safari(4721) deny(1) iokit-open AppleAPFSUserClient Violation: deny(1) iokit-open AppleAPFSUserClient

It is annoying for those maintaining a website were non-technical users have to provide files: they may conclude that the site is broken while it is not. I have no solution other than adding a warning suggesting to use another browser.

3

You can fix this is system settings > Security & Privacy > Full Disk Access. (May need to scroll down the left pane to find it).

Click the "+" and add /Applications/Safari, enable it, restart safari.

Screenshot of system preferences pane

2
  • This worked for me in Safari 14.0.2 (14610.3.7.1.10) under Mojave 10.14.6 (18G7016)
    – Peter
    Jan 25, 2021 at 19:51
  • This worked for me on Big Sur: Version11.2.3 (20D91) | Safari: Version 14.0.3 (16610.4.3.1.7). But the problem is what to do with iPhone. Do we need to tell every client to do so for safari Mar 24, 2021 at 10:35
3

Giving Safari Full Disk Access will NOT fix the problem.

I have a test page with different attributes

Click file input 1, 3, 4 is fine. Once clicked file input 2 with accept="image/*;capture=camera" it will kill all file upload on the page. But not any other page in the same domain. See a clone of the page here

need to quit safari in order to be able to select any file again with file input 1,3,4.

1

I couldn't fit this into into the comments under Michael K's answer but wanted to post incase it's useful for others. We allowed any content uploaded to our site so having to add an 'accept' attribute to fix this forced me to list out what was acceptable. Here's my list of file extensions that seem reasonable for non-coders to be uploading (from videos to documents, spreadsheets, txt files etc). It's overkill with stuff like Lotus 1-2-3 sheets etc but here it is in alphabetical order:

<input type="file" accept="audio/*,video/*,image/*,.123,.csv,.doc,.docm,.docx,.dot,.dotx,.epub,.gdoc,.gsheet,.gslides,.html,.info,.json,.key,.keynote,.log,.mcw,.md,.me,.numbers,.odm,.odp,.ods,.odt,.otp,.ots,.ott,.pages,.pdax,.pdf,.pez,.pot,.pps,.ppt,.pptx,.rtf,.shf,.sti,.sxi,.tab,.thmx,.tsv,.txt,.wk1,.wk3,.wk4,.wks,.wpd,.wps,.wpt,.wrd,.wrf,.wri,.xhtml,.xlk,.xlr,.xls,.xlsb,.xlsm,.xlsx,.xlt,.xltm,.xlw,.xml,.xps,.zip">

This is the full list I looked through: https://en.wikipedia.org/wiki/List_of_file_formats

0

I do have Full Disk Access and accept type. but still it fails to open file select dialog.

https://codepen.io/Macomatic/pen/ExgjRdK

<form method="post" enctype="multipart/form-data">
<label for="file1">File 1 label</label>
<input type="file" id="file1" name="file1" accept="image/*">
<hr>
<label for="file2">File 2 label</label>
<input type="file" id="file2" name="file2" accept="image/*;capture=camera" >
  <hr>
  <button type="submit">Submit</button>
</form>

this worked once occasionally for the file1 but never file2. however reloading the page won't allow me to select from both file inputs.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.