Forum Moderators: open

Message Too Old, No Replies

<input type="file"> and safari browser

file type inputs prevent form submitting with safari

         

whowell

11:32 am on Feb 9, 2011 (gmt 0)

10+ Year Member



Hi - hope this is the correct place to post this!

This issue only occurs for users with the safari browser.

I have a form on my aspx page with several inputs including one to allow the user to select a file to be uploaded to the server:
<input type="file" name="upload" id="upload">

The form itself uses the POST method to submit to a 2nd page "Savecomments.aspx"
<form id="commentsForm" name="commentsForm" action="SaveComments.aspx" method="POST" autocomplete="off" enctype="multipart/form-data">

If the file input is left blank (no file selected) the rest of the form submits properly

If there is a file selected it fails, none of the elements on form appear to submit correctly I can no longer see them using Request.Form on the recieving page.

Even more confusingly if I use Microsoft Visual Studio to debug my code the local version of the website it created works fine. Its when I publish to my webserver that the problems occur.

I can see no obvious issue with the server security settings and My code works fine on IE7,Firefox,Opera and Chrome.


any ideas?

Ocean10000

4:12 am on Feb 10, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I know this was a problem with OLDER versions of safari released in 2003, with it handling Keep-Alive requests properly. But I setup some testing code, which does seem to work in IE & Firefox as you said. I am waiting on Safari to install before I can test any further. Do you know if you are running on IIS 6 or 7 for your production machine? IIS 7 has Keep-Alive on by default.

below is the actual code which I am testing with.

Static Submitting Page

<html>
<body>
<form id="commentsForm" name="commentsForm" action="SaveComments.aspx" method="POST" autocomplete="off" enctype="multipart/form-data">
<input id="Text1" name="Text1" type="text" /><br />
<br />
<input type="file" name="upload" id="upload"><br />
<input id="Submit1" type="submit" value="submit" /></form>
</body>
</html>


SaveComments.aspx - my debugging version.
Which will list out all the files uploaded and the Form values as well.

<script runat ="server" language ="C#">
private void Page_Load(object sender, System.EventArgs e)
{
Response.ContentType = "text/html";
for (int i = 0;i <= Request.Files.Count - 1;i++)
{
Response.Write("[" + Request.Files.Keys[i] + "][FileName=");
Response.Write("\"" + Request.Files[i].FileName + "\"]");
Response.Write("[ContentLength=");
Response.Write("\"" + Request.Files[i].ContentLength + "\"]<br>");
}
for (int i = 0;i <= Request.Form.Count - 1;i++)
{
Response.Write("[" +Request.Form.Keys[i] + "] = " + Request.Form[i] + "<br/>");
}
}
</script>

Ocean10000

4:21 am on Feb 10, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I tested it with Safari (Windows)Version/5.0.3 and it worked just fine with the code above? What version of Safari are you testing with? I am testing against it on a windows 2003 server running IIS 6.

output should look something like this.

[upload][FileName="Old Charter.txt"][ContentLength="3933"]
[Text1] = test

whowell

8:56 am on Feb 10, 2011 (gmt 0)

10+ Year Member



Hi Ocean10000
Thanks for looking into this for me
I tried your code but on my system but it returns nothing at all in safari (It works fine on other browsers)

Our systems look much the same:
My version of safari is 5.0.3 (7533.19.4)
I'm running on a Windows 2003 server with IIS v6.0
I am using an older version of ASP.NET - 2.0.50727 - I might try 4.0 and see if that has any effect!

Thanks again for your help

whowell

9:11 am on Feb 10, 2011 (gmt 0)

10+ Year Member



Hi again

Tried ASP.NET 4 but still the same issue in safari:
If I select a file the recieving page recieves nothing from the form - If I don't select a file it recieves the form ok

I tried selecting a really small file but that still didn't work.

our IIS server is a virtual one but I don't think that is the issue

Ocean10000

3:25 pm on Feb 10, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Do you have any javascript which touches the enctype property of the form on the submitting page?

whowell

3:41 pm on Feb 10, 2011 (gmt 0)

10+ Year Member



No Javascript at all on the submitting page or Recieving one
The code I am using is basically just the code you tested with

Fotiman

3:44 pm on Feb 10, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Perhaps try using a packet sniffing tool like Wireshark to examine the network traffic and compare the differences between what is being sent/received in other browsers with what is being sent/received in Safari?