Reputation: 141
I am using dojo 1.7.2 I have bee trying to get the file uploader to work with a REST service in PHP. Here is my function:
dojo.connect(dijit.byId("CNCFileUploader"), "onComplete", function(dataArray){
alert("onComplete Fired!");
dojo.forEach(dojo.isArray(dataArray) ? dataArray : [dataArray], function(resp){
console.log("display:", resp.file, resp.duplicates);
});
});
This is my markup:
<div data-dojo-type="dijit.Dialog" id="addCncIdsFileDialg" >
<form method="post" data-dojo-type="dijit.form.Form" id="addCncIdsFileFrm" enctype="multipart/form-data" action="CartService.php/cart/156568/cncidfiles">
<fieldset>
<legend>Upload File(s) with CNC_IDs</legend>
<div align="center">
<input type="file" multiple="true" name="CNCFileUploader" id="CNCFileUploader" data-dojo-type="dojox.form.Uploader" uploadOnSelect="false" /> <br/>
<button data-dojo-type="dijit.form.Button" type="submit" data-dojo-props="onClick:function(){dijit.byId('addCncIdsFileDialg').hide();}" id="cncIdsFSubmitBttn">OK</button>
<button data-dojo-type="dijit.form.Button" type="button" data-dojo-props="onClick:function(){dijit.byId('addCncIdsFileDialg').hide();}" id="cncIdsFCancelBttn" >Cancel</button>
</div>
<div id="CNC_IDfiles" dojoType="dojox.form.uploader.FileList" uploaderId="CNCFileUploader"></div>
</fieldset>
I never see the alert. For IE9 I see that the file is uploaded and processed. Interestingly while I select a single file, the logs show a second file with a null name and error=4. Also while the onComplete never happens, IE9 prompts me if I want to save cncidfiles from local host. The upload will only work the first time after that it does nothing and never again after that.
When I changed the multiple flag to false, the uploader stopped working entirely. With the following written to the JavaScript console:
TypeError: Unable to get value of the property 'value': object is null or undefined
TypeError: Unable to get value of the property 'value': object is null or undefined
A second problem is that when I use Google Chrome, the file is sent every time, but what I see on the server is very different from what dojo has documented in their Uploadfile.php.
I believe that dojox.form.Uploader is severely broken in 1.7.2 in several significant ways!
Out of frustration, I tried using dojo.io.iframe.send but while Chrome works fine, IE9 still acts like it wants to download cncidfiles and also only works the first time.
Upvotes: 1
Views: 3045
Reputation: 8641
Ahuh... Poor uploader widget... :)
Well, check out http://clubajax.org/the-new-dojo-html5-multi-file-uploader/ and see if there's a comment here (on html5 uploader authors post).
Your question does not state how you do this, but you need to extend your uploader either of the plugins, IFrame
/ HTML5
or Flash
or the onComplete is not an API hook.. In other words, its not defined in dojox/form/Uploader. You should use a sniff method, determining if it is IE or 'other'. For IE extend it with Flash
and any other, use HTML5 (which has IFrame as fallback)
// this must be BeFore dojo.ready (and before parser runs)!
if(dojo.isIE) dojo.require("dojox.form.uploader.Flash");
else dojo.require("dojox.form.uploader.HTML5");
Upvotes: 1