Opened 7 years ago

Closed 7 years ago

Last modified 6 years ago

#15151 closed defect (fixed)

UploadFile.php not working on single file uploads

Reported by: adlerweb Owned by: Mike Wilcox
Priority: undecided Milestone: 1.9
Component: DojoX Uploader Version: 1.7.2
Keywords: Cc:
Blocked By: Blocking:


When feeding UploadFile?.php from a source using "HTML single POST" (like "Inline Browse Button Form Post Test" from test_Uploader.html) the upload itself works but dojo does not recognize the successful completion (i guess onComplete() doesn't get fired). Firefox' error console shows "JSON.parse: unexpected character".

For reference here an UploadFile?.php-Output in case of the named "HTML single POST" (multiple="false") captured by HttpFox?:

<textarea style="width:600px; height:150px;">{"file":"..\/tests\/uploads\/test.jpg","name":"test.jpg","width":2272,"height":1704,"type":"jpg","size":2060485,"additionalParams":{"album":"Summer Vacation","year":"2011"}}</textarea>

This output is sent back on multi file uploads using "HTML5 multi file input" (multiple="true"):


As you can see the correctly working multi-upload does not return the JSON-Data inside a <textarea> - i guess the http-post-tree is missing a return-function like on other methods. If i add the following lines at line 290 (current git) it seems to work.

+ $data = $json->encode($htmldata);
+ trace($data);
+ print $data;
+ return $data;

Note: Other methods like rmFiles also got no return on success - i have not tested but i guess these are broken too. Is this whole <textarea>-JSON-Wrapping even applicaple with current dojo?

Change History (11)

comment:1 Changed 7 years ago by jeff_l

I have a similar problem, that seems to have developed within the past couple of months. As of last July, the following chunk of code was rendering just fine, but now I can't manage to get the onComplete event to fire, no matter what combination of plugins I require (HTML5, IFrame, Flash) as described in . We're on Dojo 1.7, and using the latest versions of Firefox and IE9. Perhaps something has changed recently in the browsers.

<div style="display:none" id="fileUploadDialog" data-dojo-type="dijit.Dialog" title="Add/Modify? collateral images">

<div id="dynamicUploadList"></div> <form method="post" action="/wle/EstimatorServlet" id="uploadForm" enctype="multipart/form-data">


<legend>Upload images</legend>

<input type="hidden" name="pgTitle" value="collateral"> <input type="hidden" id="IEIFrame" name="addTextArea" value="0"> <input class="browseButton" style="width:160px" name="uploader" multiple="true" type="file" data-dojo-type="dojox.form.Uploader" label="Select Image File(s)" id="uploader" oncomplete="this.reset();updateCollateralList();">

<input type="button" id="remBtn" label="Clear" data-dojo-type="dijit.form.Button" onclick='dijit.byId("uploader").reset()'> <input type="submit" label="Upload" data-dojo-type="dijit.form.Button" onclick= 'if (dojo.isIE) { dojo.byId("IEIFrame").value = 1; }'> <div id="files" dojotype="dojox.form.uploader.FileList?" uploaderid="uploader"></div>




comment:2 Changed 7 years ago by Mike Wilcox

Status: newassigned

One thing I found while testing this is that Uploader does not work perfectly with AMD. So this fails:


But this works:


adlerweb, I think that might help you. If you are getting a textarea, something is wrong, that's only for iframes.

jeff_l, your code seems to work. Please check the server is handling the request properly.

Test that you have the uploader plugin that you expect:

var u = dijit.byId('uploader');

comment:3 Changed 7 years ago by jeff_l

mwilcox, thanks for looking into this. When I added your suggested diagnostic code, just after the closing </div> in my excerpt above, I saw the following error in the console: "u is undefined"

comment:4 Changed 7 years ago by Mike Wilcox

Oh, that might not have happened at the right time. Here is more fleshes out code:

function(dojo, Button, Uploader, FileList, uFlash, dr, parser){
	parser.parse(); /// <----------------- after this
	var u = dijit.byId('uploader');
	console.log(u.uploadType, u);

comment:5 Changed 7 years ago by jeff_l

mwilcox, sorry for being such a dimwit, but my app doesn't have anyplace where it does an explicit parse(), so I'm not seeing an obviously correct place to insert the "var u" assignment.

comment:6 Changed 7 years ago by Mike Wilcox

How are you parsing your widgets? Are you using the old renderer with parseOnLoad=true in dojoConfig? You could put it on dojo.ready();

You also could just use a setTimeout since this is just for debugging.

comment:7 Changed 7 years ago by jeff_l

Yes, we're specifying parseOnLoad=true in dojoConfig. Following your suggestions, I messed around with dojo.ready() and setTimeout() but it's not cooperating, probably since I don't really know what I'm doing.

Before I burn out your patience -- Is there one very specific step I could take to try to debug this problem? And please don't worry about offending me by being explicit, spelling things out as you would to a nearly complete newbie at Dojo and JavaScript?. I've been doing industrial Java for a couple of decades, but am still getting the hang of this Web stuff.

comment:8 Changed 7 years ago by jeff_l

We solved our problem. It turned out that we had neglected to include a unique session ID in our submitted <form> element. A couple of months ago we added multi-session support to our app, which involved tagging each new browser tab with a unique ID. When we added a hidden <input> with the sessionID, it solved the problem. mwilcox, thanks for your suggestions along the way.

comment:9 Changed 7 years ago by Mike Wilcox

Resolution: fixed
Status: assignedclosed

I fixed the line of code that was append s[] to the filename to do it even if it is single file. This works, but may cause troubles backcompat with current workarounds.

comment:10 Changed 7 years ago by bill

Milestone: tbd1.9

(In [30328]) Fixes: #14768, #15151, #16293, #14914, #14811, #11885, #14075 converted Uploader to use AMD properly which required discarding the plugin approach. All functionality is now included in Uploader. plugins remain for backcompat in order to throw warnings.

comment:11 Changed 6 years ago by xMartin

Not happy with the solution of always adding "s[]". I can't configure the attribute name any more which breaks my app. I don't want to change my server to accept an array of files, it only supports single uploads.

Note: See TracTickets for help on using tickets.