angularjs - 'Unexpected token' in AJAX upload of multipart/form-data in angular.js 1.3.0 -
The following code for texture upload was working in angularjs 1.2.26, but when I got my web application 1.3.0 .
HTML code
& lt; Input file-model = "file" name = "file" type = "file" & gt;
The file modem director
App Directional ('file model', ['$ parse', function ($ paras)) {return {restricted: 'A', link: function (scope, element, ethers) {var model = $ parse (attrs.fileModel); Var modelsetter = model.Singgi; Element Bind ('change', function () {radius. $ Apply (function () {ModelSetter (field, element [0]. Files [0]);});}). $ ("Reset", function () {element.val (null);})}}}}}]);
The content type will not work by selecting "Multipart / Form-Data" in Upload Function - 1.2.26. But with "undefined", there will be some magic in the form of an angle of content-type that it will work.
var upload = function (textureUploadUrl) {var formData = new formData (); FormData.append ('name', $ scope.name); FormData.append ('file', $ scope.file); $ Http.post (textureUploadUrl, formData, {transformRequest: angular.identity, headers: {'content-type': undefined}}. Success (function (uploaded cloth) {console.log (uploaded garment); / / Process ahead of the uploaded mix}}}}
Error:
Syntax error: unexpected token on object h. (Native) to JSN (Https://ajax.googleapis.com/ajax/libs/angularjs/1.3.0/angular.js:1104:14) HttpResponseTransform at default (https://ajax.googleapis.com/ajax/libs/angularjs/1.3 .0 / angular.js: 8572: 18) at https: //ajax.googleapis.com/ajax/libs/angularjs/1.3.0/angular.js: 8517: 12 for each (https: // ajax. Googleapis.com/ajax/li Bs / angularjs / 1.3.0 / angular .js: 335: 20) Transformatata (https://ajax.googleapis.com/ajax/libs/angularjs/1.3.0/angular.js:8516:3) Response to Transform ( Https://ajax.googleapis.com) /ajax/libs/angularjs/1.3.0/angular.js:9224:23) Questions on Process (https://ajax.googleapis.com/ajax/libs/angularjs/1.3 .0 / angular.js: 12914: 27) at scopes at https://ajax.googleapis.com/ajax/libs/angularjs/1.3.0/angular.js:1293027 $ Eval (https://ajax.googleapis.com/ajax/libs/angularjs/ 1.3.0 / angular .js: 14123: 28)
Does anyone want to do this work Know the way to live in the new version?
UPDATE
I have solved the problem a little bit. It does not work with 1.3.0-RC.5, but the previous version RC4) This works with. So, I am currently trying to figure out which changes will lead my problem. Here it is. Server
The problem was in the feedback header of my text upload request on the server side Spring MVC used and mapped a request like that, but without output
specification:
@RequestMapping (value = "/ uploadUrl", method = RequestMethod. POST, Production = "Text / plain; Charset = UTF-8") @ ResponseBody Public String TexturePoOut ST (HTTPSArlate Request) (// Create service URL for upload texture and textured return service URL;}
Then, as the content type, text / plain
Without specifying, Spring automatically uses application / json
as a content-type and this causes angular.js to 1.3.0-rc.5 () since JSON. My text upload gives url pointing to the location where the image is served. Interpretation is. Because it is a simple string, so described results in an error message, so do not forget to specify the correct content type in your server responses: -)
Comments
Post a Comment