[Dojo-interest] dojo.iframe.io.send hanging after 1 or 2 file uploads in Safari

123 views
Skip to first unread message

Jette Derriche

unread,
Sep 28, 2009, 4:35:56 AM9/28/09
to Dojo Interest
Hi,

Last week I made a post about dojo.iframe.io.send and Safari on Mac. I
thought it was solved, but now I have new information.

When uploading a file using Safari on Mac, it works the first time, and
maybe a second time. After that, the next upload just hangs.

This leads me to believe that I need to reset something. I just don't
know how and what. Any ideas?

The test was done in Safari v4 with dojo v1.2.3.

Here is a complete test case (remember to correct your paths to dojo).

CLIENT SIDE:
-------------------------------------
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<head>
<title>dojo.io.iframe.send test case</title>
</head>
<link rel="stylesheet" type="text/css"
href="dojo1/dojo/resources/dojo.css">
<link rel="stylesheet" type="text/css"
href="dojo1/dijit/themes/tundra/tundra.css">
<script type="text/javascript" src="dojo1/dojo/dojo.js"
djConfig="parseOnLoad: true, locale:'end', usePlainJson: true"></script>
<script type="text/javascript">
dojo.require("dojo.parser");
dojo.require("dojo.io.iframe");
function fileupload(formId,functionName) {
dojo.io.iframe.send({
form: formId,
handleAs: 'json',
load: function(data){

//Call another function
eval(functionName+'(data)');

},
error: function(data,ioArgs) { alert(data); return data; }
});
}

function anotherFunc(data) {
alert('Message from server: '+data.message);
}
</script>
</head>
<body style="padding:50px">


<form id="fileupload" method="post" action="serverside.php"
enctype="multipart/form-data">
<input name="action" value="fileupload" type="hidden">
<input name="args[recipientId]" value="430" type="hidden">
<input name="args[messageId]" value="1125765" type="hidden">
<input name="args[type]" value="attach" type="hidden">
<input name="file" id="modalFileUploadField" type="file">
<input value="Upload file"
onclick="fileupload('fileupload','anotherFunc')" type="button">
</form>

</body>
</html>
-------------------------------------

SERVER SIDE (serverside.php):
-------------------------------------

<?php
if (isset($_FILES['file']['size'])) {
$error = '0';
$success = '1';
$msg = 'The FILES array was successfully set';
} else {
$error = '1';
$success = '0';
$msg = 'Failed: no FILES array';
}
$ary = array('error' => '0','success' => $success, 'message' => $msg);
$retval = json_encode($ary);
$retval =
"<html><head></head><body><textarea>$retval</textarea></body></html>";
echo $retval;
------------------------------------

/Jette

_______________________________________________
FAQ: http://dojotoolkit.org/support/faq
Book: http://docs.dojocampus.org
Dojo-i...@mail.dojotoolkit.org
http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest

Mike Wilcox

unread,
Sep 28, 2009, 7:56:21 AM9/28/09
to dojo-i...@mail.dojotoolkit.org
It works for me in dojo 1.4. There were some changes to the iframe,
but I think it was only for builds.

The only thing I see wrong is that you have two </head> tags.

Sorry that's not much help. Try the trunk and see if it fails there?

Mike Wilcox
Software Engineer
SitePen, Inc.
http://www.sitepen.com

Jette Derriche

unread,
Sep 28, 2009, 12:17:03 PM9/28/09
to dojo-i...@mail.dojotoolkit.org
On man, 2009-09-28 at 06:56 -0500, Mike Wilcox wrote:
> It works for me in dojo 1.4. There were some changes to the iframe,
> but I think it was only for builds.
>
> The only thing I see wrong is that you have two </head> tags.
>

No, I have a start-tag, and and end-tag:

"<html><head></head><body><textarea>$retval</textarea></body></html>";

Also, it always works the first time (and somtimes the second), so the
return value is probably not the cause.

> Sorry that's not much help. Try the trunk and see if it fails there?

Yeah, I should probably use this as an opportunity to upgrade dojo.

Thank you for taking the time :-)

Jette Derriche

unread,
Oct 22, 2009, 6:16:47 PM10/22/09
to dojo-i...@mail.dojotoolkit.org
I have spent many hours on this bug, so I'll probably save someone some
time by posting my solution.

To sum it up, I've been struggling getting file uploads working in
Safari with dojo.io.iframe.send.

It turns out, that the problem is not dojo or using ajax in general. I
noticed that the same error occurred with plain old html file upload
forms.

The bug is in the way Safari handles the connection:
https://bugs.webkit.org/show_bug.cgi?id=5760

I added this to the virtual host in the Apache conf file, and now it
works like a charm:

BrowserMatch Safari nokeepalive

Must say I am surprised that this has been an issue since 2005 :-/

The symptoms of this issue are:

File uploads work sporadically with Safari. The larger the file is, the
more likely it is to fail. The browser seems to do something (the
addressbar says 'Loading...'), but nothing is actually sent to the
server. It fails consistently if the same file (around 1 mb) is uploaded
twice via the same form.

/Jette

Nicola Piccinini

unread,
Nov 14, 2009, 11:26:25 AM11/14/09
to dojo-i...@dojotoolkit.org
Reply all
Reply to author
Forward
0 new messages