how to get image file out of json body of request?

42 views
Skip to first unread message

Krishnakant

unread,
May 26, 2016, 3:02:47 AM5/26/16
to pylons-discuss
Hello,
I have been working on an accounting software which is being developed
as a RESTful api at the server side and a usual MVC based front end,
both made in Pyramid.
One unique feature of this software is that we have scanned images in
the voucher.
I wish to know two things, one is slightly off topic.
first, how do I send a request containing JSON object having all the
form fields + a png or jpeg image?
My requests from jinja template are ajax based and call a view at the
front end side.
So this view should be able to find this image in the request.params
method or what ever is suitable.
So this vew then talks to a separate REST API based service, again done
in Pyramid.
What happens here is that all the parameters from the request are packed
into a Python dictionary and then we do json.dumps on that packet.
The this jsonified object is sent to the rest api.
In the server we get this object using request.json_body and then work
on it.
Secondly, my server should be able to correctly get the image form the
json_body and then store it on the hard disk.
In all this I am not aware of how image is handled throughout all the
transfer process.
Can some one help?
happy hacking.
Krishnakant.

Jonathan Vanasco

unread,
May 26, 2016, 11:21:09 AM5/26/16
to pylons-discuss, krm...@openmailbox.org


On Thursday, May 26, 2016 at 3:02:47 AM UTC-4, Krishnakant wrote:
first, how do I send a request containing JSON object having all the
form fields + a png or jpeg image?

option 1- have your ajax script submit a POST with the image in multipart file fields
option 2 - have your ajax script submit a GET or POST with the image encoded into base64 on your submitted JSON document

Secondly, my server should be able to correctly get the image form the
json_body and then store it on the hard disk.

 that various form processing libraries (deform, formencode, etc) have code that shows how to process file uploads

Krishnakant

unread,
May 26, 2016, 11:25:28 AM5/26/16
to pylons-...@googlegroups.com
Will such libraries also work with json objects with key:value where value is some raw stream like base64 encoded upload?

Happy hacking.
Krishnakant.
Reply all
Reply to author
Forward
0 new messages