**** BEGIN LOGGING AT Mon Nov 12 02:59:58 2012 Nov 12 16:33:58 hey guys, how do I send a FormData object using enyo.Ajax? Nov 12 16:35:56 what's the structure of a FormData object? does it get passed as a parameter? Nov 12 16:39:56 I've never really used a FormData object, but I think you can set the contentType parameter when you create a new enyo.Ajax object, and then you can pass your FormData object as an argument to enyo.Ajax.go(); Nov 12 16:44:08 you would normally use: xhr.send(formdata_object) Nov 12 16:47:28 so, a quick google shows there was a bug with it, but it's been fixed, and the test cases there do something like Nov 12 16:48:08 new enyo.Ajax({method: "POST", postBody: new FormData(), url: my.url.com}); Nov 12 16:48:20 call the go() method Nov 12 16:50:06 check out https://github.com/enyojs/enyo/commit/8b58edad97e091d8a15155f87b864a64fb81c722 on line 81, in the 3rd file Nov 12 17:01:09 ok, thanks :) Nov 12 18:36:07 hey summatusmentis, your suggestion looks like it is working, but PHP is not seeing it in the $_FILES array. :( Nov 12 18:37:11 what're the headers being sent? specifically, what's the contentType? Nov 12 18:48:56 octet stream Nov 12 18:52:06 it's supposed to be "multipart/form-data" right? Nov 12 18:54:14 also, we're reaching the end of my knowledge on this issue, my guess is that the server-side is mis-interpreting what's coming in, which is why it's not being put into $_FILES Nov 12 18:54:45 I would double check that your request is doing the right thing (that is, the body and headers are correct) Nov 12 18:55:07 maybe watch the request that a browser would send when the form is populated that way, and compare? Nov 12 18:59:19 I did watch the request Nov 12 18:59:32 that's how I know PHP is seeing the request Nov 12 18:59:43 but not recognizing it as a file Nov 12 18:59:58 interesting, what if you set contentType: "multipart/form-data" in the Ajax call? Nov 12 19:00:03 how would I set it to multipart/form-data? Nov 12 19:00:30 new enyo.Ajax({method: "POST", postBody: new FormData(), url: my.url.com, contentType: "multipart/form-data"}); Nov 12 19:00:35 doesn't content-type change how I perceive what I receive? Nov 12 19:01:06 I think it affects how the server perceives what you send when put in the request headers Nov 12 19:01:19 ah Nov 12 19:01:20 the response headers may also have a content-type, which will change how you perceive what you receive Nov 12 19:01:55 my understanding is that it's a given network-node's identification of what is being sent Nov 12 19:02:40 what types of responses do you get form the server when you post to it? Nov 12 19:02:47 are you getting error codes at all? Nov 12 19:02:58 still sends it as octet stream Nov 12 19:03:29 the only errors PHP is giving me is that I'm trying to go to an unknown index in the $_FILES array Nov 12 19:03:44 and that's because it doesn't realize it's getting a file Nov 12 19:04:39 can you pastebin your code? Are you creating the FormData object correctly? Nov 12 19:05:06 you also have the mimeType parameter that you can pass to the Ajax, which might help Nov 12 19:05:31 or put it in jsfiddle Nov 12 19:06:05 I'm just using new FormData() and appending to it Nov 12 19:06:08 then sending Nov 12 19:06:14 not very complicated Nov 12 19:06:16 yeah, ok, that sounds right Nov 12 19:06:38 the file is posting fine, PHP just isn't seeing it as a file Nov 12 19:06:49 it even shows up in PHP's raw post data Nov 12 19:07:05 hrm Nov 12 19:07:33 then my guess is you're missing something crucial in the construction of the request, but I can't tell you what Nov 12 19:15:33 I found one guy that says $_FILES doesn't populate for xhr requests, and everyone else acts like it does Nov 12 19:15:43 this is really frustrating Nov 12 19:19:56 some searching indicates that javascript shouldn't have access to the file contents, which may be why $_FILES isn't populating Nov 12 19:20:41 which seems odd to me, but it's pretty consisten Nov 12 19:20:44 consistent* Nov 12 19:21:47 although, there's a way to do it w/ HTML5? Nov 12 19:22:17 is this a mobile app? Are you using PhoneGap? Nov 12 19:22:20 $_FILES is PHP Nov 12 19:22:24 not JS Nov 12 19:22:55 also, can't do anything w/ HTML5 because corporations suck and love to use IE Nov 12 19:22:58 right, I know Nov 12 19:23:05 ok Nov 12 19:23:33 but if the JS can't upload the contents of the file, the php server-side may not be recognizing that it's a file Nov 12 19:23:48 are the sizes of the requests being sent the same size as the file + a little bit extra? Nov 12 19:25:07 the JS is sending the file, tho Nov 12 19:25:17 PHP sees it in the RAW post data Nov 12 19:25:48 ok, odd Nov 12 19:25:58 can you jsfiddle your enyo code? Nov 12 19:27:44 just a sec, I see the wrong content-type in the request header in firebug. Nov 12 19:28:20 yeah, I think that's why Nov 12 19:29:22 well, I tried your contentType suggestion before and that didn't work Nov 12 19:29:38 but I didn't check if it actually changed anything in the header Nov 12 19:31:09 I changed the contentType and still get the same errors Nov 12 19:32:20 can you put your code someplace? I think I'm visualizing this properly, but I just want to see for sure Nov 12 19:33:29 http://pastebin.mozilla.org/1937402 Nov 12 19:34:27 ignore the name, it's a bond reference :P Nov 12 19:35:48 is populate getting called? Nov 12 19:36:50 it don't remember. But it worked back when I was just posting the info from the textarea instead of trying to do a file upload Nov 12 19:37:18 I wonder if you should be creating and populating the FormData object prior to setting the postBody of the WebService Nov 12 19:37:39 that wouldn't make any difference Nov 12 19:37:50 we know the file gets added to the post body Nov 12 19:37:56 hrm, ok Nov 12 19:38:05 why do you have handleAs json? Nov 12 19:38:29 it's probably not affecting anything, but I figured I'd ask Nov 12 19:38:44 because my PHP script will take that file, run a validator written in awk on it, and return the output in json Nov 12 19:39:29 so, if you could verify that your populate() handler is running, that'll help Nov 12 19:39:56 and you could then log inEvent.xhr and see what the response code is (make sure it's returning 200) Nov 12 19:40:14 It's returning 200 Nov 12 19:40:25 but my response has PHP errors in it Nov 12 19:40:32 because PHP doesn't see the file Nov 12 19:42:07 and if you remove the contentType portion of the WebService, does that change behavior at all? Nov 12 19:44:36 same error, but the contentType of the request becomes x-www-... Nov 12 19:44:42 also, it shouldn't matter I don't think, but convention is that the method should be uppercase Nov 12 19:45:01 o,o Nov 12 19:45:05 yeah, contentType defaults to x-www-urlencoding (or whatever) Nov 12 19:45:17 that's not the convention in the documentation Nov 12 19:45:27 http://enyojs.com/api/#enyo.AjaxProperties Nov 12 19:45:31 also, only classes should be uppercase in OOP Nov 12 19:45:31 yeah, method: "POST" Nov 12 19:45:42 oh, THAT method Nov 12 19:45:44 XD Nov 12 19:45:49 yes, sorry, not the function name Nov 12 19:46:08 that doesn't matter, my posts have been working fine w/ lowercase Nov 12 19:46:27 yeah, it shouldn't matter Nov 12 19:46:43 This was working code until I tried to make it do a file upload instead of posted text Nov 12 19:46:44 what's the mime-type of the file? Nov 12 19:46:56 it's just plaintext Nov 12 19:47:00 there's likely just one thing that isn't clicking Nov 12 19:47:16 fxspec06: d'you know anything about posting FormData objects to a PHP server? Nov 12 19:51:06 I think he's just idle Nov 12 19:51:14 probably Nov 12 19:51:17 hrm, I'm out of ideas Nov 12 19:51:36 when I get to this stage, I usually just start fiddling with it, and reading headers/googling Nov 12 19:52:55 lol, I've been doing that this whole time XD Nov 12 19:55:55 there's something simple that you're gonna feel stupid about when you figure it out Nov 12 19:56:09 ikr? Nov 12 19:59:02 it looks reasonable to me, sorry I can't be of more help Nov 12 19:59:13 I don't use FormData() objects Nov 12 20:02:14 s'ok Nov 12 20:03:17 what version of enyo are you using? Nov 12 20:03:37 that bug I linked you to earlier? just got merged into master 4 days ago Nov 12 20:04:01 so, unless you've pulled from github recently, you won't have the fix Nov 12 20:05:26 I bet that's the issue Nov 12 20:05:38 I grabbed the latest master after you told me that Nov 12 20:05:45 and have been using that all day Nov 12 20:05:49 oh Nov 12 20:05:53 then nevermind Nov 12 20:06:00 I didn't notice the timeframe on that bug earlier Nov 12 20:46:08 so I think the problem may be caused w/ how the Enyo XHR wrappers work -_- Nov 12 20:57:45 this is really frustrating Nov 12 21:37:03 what specifically do you think is wrong? Nov 12 21:50:33 summatusmentis: It seems there is a problem with trying to set the headers with xhr for uploading files Nov 12 21:50:50 if you don't set a header, then it autosets the correct one Nov 12 21:51:21 but this won't work w/ enyo's XHR wrappers, because they have a default content-type Nov 12 21:51:27 etc. Nov 12 21:51:36 huh, interesting Nov 12 21:52:47 yea :( Nov 12 21:53:19 if the wrappers allowed you to build and pass your own XHR object, it would probably work Nov 12 21:55:00 that's what the xhrFields parameter does Nov 12 21:55:02 I think Nov 12 21:57:33 nah, that's for "extra parameters" Nov 12 21:58:33 are you sure it doesn't overwrite defaults also? Nov 12 22:33:05 summatusmentis: extra tends to mean extra **** ENDING LOGGING AT Tue Nov 13 02:59:57 2012