[SOLVED] need help debugging REST POST upload problem

wewowe

Joined: 2012-04-26
Posts: 5
Posted: Thu, 2012-04-26 03:58

I am running into a problem trying to upload photos using the REST module.
I get this error from gallery3:

2012-04-25 20:04:40 -07:00 --- error: Rest_Exception [ 400 ]: Bad Request
/srv/http/gallery3/modules/gallery/helpers/item_rest.php [ 185 ]
#0 [internal function]: item_rest_Core::post(Object(stdClass))
#1 /srv/http/gallery3/modules/rest/controllers/rest.php(104): call_user_func(Array, Object(stdClass))
#2 [internal function]: Rest_Controller->__call('item', Array)
#3 /srv/http/gallery3/system/core/Kohana.php(331): ReflectionMethod->invokeArgs(Object(Rest_Controller), Array)
#4 [internal function]: Kohana_Core::instance(NULL)
#5 /srv/http/gallery3/system/core/Event.php(208): call_user_func_array(Array, Array)
#6 /srv/http/gallery3/application/Bootstrap.php(67): Event_Core::run('system.execute')
#7 /srv/http/gallery3/index.php(102): require('/srv/http/galle...')
#8 {main}
2012-04-25 20:04:40 -07:00 --- error: Missing messages entry kohana/core.errors.400 for message kohana/core
2012-04-25 20:04:40 -07:00 --- error: Rest error details: Array
(
[errors] => Array
(
[type] => invalid
)

)

Is there a way to increase the amount of logging that the REST module does? I am pretty sure the problem
is some kind of malformed data being sent to Gallerry3 - but where?

Thanks for any ideas.

 
wewowe

Joined: 2012-04-26
Posts: 5
Posted: Thu, 2012-04-26 05:02

I did some more digging and I can see that in item_rest.php $request->params->entity->type is null.

Most like the cause is a malformed http request. This is what I have:

--roPK9J3DoG4ZWP6etiDuJ97h-zeNAph
Content-Disposition: form-data; name="entity"
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

{"description":"more text description","type":"photo","name":"i16455.jpg","title":"this is a title"}
--roPK9J3DoG4ZWP6etiDuJ97h-zeNAph
Content-Disposition: form-data; name="file"; filename="i16455.jpg"
Content-Type: application/octet-stream
Content-Transfer-Encoding: binary

<binary image>
--roPK9J3DoG4ZWP6etiDuJ97h-zeNAph--

Does that look OK? I guess I want to find the place where the request is unpacked - and
turn on debugging in that area - so I can see why my data is not acceptable...

Thanks.

 
wewowe

Joined: 2012-04-26
Posts: 5
Posted: Fri, 2012-04-27 05:12

Solved -- I was building the http headers incorrectly. My requests were missing the
content-type: multipart/form-data ... stuff. Once I added that it started working!!

 
floridave
floridave's picture

Joined: 2003-12-22
Posts: 26091
Posted: Fri, 2012-04-27 16:13

Thanks for the followup. I have never used REST so could not comment. Glad you got it sorted.

Dave
_____________________________________________
Blog & G2 || floridave - Gallery Team

 
Jakez
Jakez's picture

Joined: 2004-03-24
Posts: 23
Posted: Tue, 2012-11-20 04:14

Thx for writing down the answer - helped me a lot! ;)