define ([ "dojo/_base/array", // array.forEach array.map "dojo/_base/declare", // declare "dojo/dom", "dojo/io/iframe", "dojox/xml/parser", "dojo/dom-style" ], function(array, declare, dom, iframe, xmlParser, domStyle) { var ContentStreamer = declare("obno.core.stream.ContentStreamer", null, { constructor : function(serverConfig) { serverConfig = dojo.mixin({}, serverConfig); this._serverUrl = serverConfig.serverUrl || null; if (this._serverUrl == null) { return; } this._timeout = serverConfig.serverTimeout || 30000; }, stream : function(content, expectStatusResult /*boolean*/, retContentType, onSuccess /*function*/, onError /* function */) { var postContent = content; this._createTemporayForm(); var ret = null; var _handleAs = 'json'; if (retContentType) { _handleAs = retContentType; } var dfr = iframe.send( { url: this._serverUrl, content: postContent, form: this._temporaryUploadForm, method: "POST", timeout: this._timeout, handleAs: _handleAs, error: function(response, ioArgs) { if (!response) { //we do no know what it is, so do nothing return; } //cancel errors will be repored as so if (!response && !expectStatusResult) { //we are ok, do not do anything return; } if (response.message === 'Deferred Cancelled') { //do nothing return; } }, load : function(response, ioArgs) { if (onSuccess) { onSuccess(response); } } }); xmlParser.removeChildren(this._temporaryUploadForm); return {dfr : dfr, ret : ret}; }, _createTemporayForm : function() { this._temporaryUploadForm = document.createElement('form'); domStyle.set(this._temporaryUploadForm, 'display', 'none'); this._temporaryUploadForm.setAttribute("enctype","multipart/form-data"); dojo.body().appendChild(this._temporaryUploadForm); } }); return ContentStreamer; });