Read binary data in python

274 views
Skip to first unread message

František Kolář

unread,
Jul 25, 2013, 10:23:40 AM7/25/13
to mongod...@googlegroups.com
Hi Group, 

I have saved bin data in java and not really sure how to read it in python back. 



>> collection.find_one({"identity": "2000000012"})

{u'state': u'Approved', u'received': datetime.datetime(2012, 11, 11, 16, 23, 57, 670000), u'_type': u'rawdocument', u'preview': [{u'contentType': u'image/jpg', u'_type': u'eu.phobos.data.statement.BinaryData', u'pageNumber': 1, u'binaryData': Binary('\xff\xd8\xff\xe0\x00\x10JFIF\x00\x01\x02\x00\x00\x01\x00\x01\x00\x00\xff\xdb\x00C\x00\x08\x06\x06\x07\x06\x05\x08\x07\x07\x07\t\t\x08\n\x0c\x14\r\x0c\x0b\x0b\x0c\x19\x12\x13\x0f\x14\x1d\x1a\x1f\x1e\x1d\x1a\x1c\x1c $.\' ",#\x1c\x1c(7),01444\x1f\'9=82<.342\xff\xdb\x00C\x01\t\t\t\x0c\x0b\x0c\x18\r\r\x182!\x1c!22222222222222222222222222222222222222222222222222\xff\xc0\x00\x11\x08\x04b\x03\x19\x03\x01"\x00\x


Any idea how to read it back from the field. u'binaryData : Binary('\xff\xd8\xff\xe0\x00\x10J...., 0 ) 


Thank you for any help. 

FK

Bernie Hackett

unread,
Jul 25, 2013, 10:57:31 AM7/25/13
to mongod...@googlegroups.com
The Binary type in PyMongo is just a subtype of str (in python 2) or
bytes (in python 3). You don't have to do any conversion to work with
the data. Data stored as BSON Binary is not altered in any way.
> --
> --
> You received this message because you are subscribed to the Google
> Groups "mongodb-user" group.
> To post to this group, send email to mongod...@googlegroups.com
> To unsubscribe from this group, send email to
> mongodb-user...@googlegroups.com
> See also the IRC channel -- freenode.net#mongodb
>
> ---
> You received this message because you are subscribed to the Google Groups
> "mongodb-user" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to mongodb-user...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

František Kolář

unread,
Jul 25, 2013, 3:38:48 PM7/25/13
to mongod...@googlegroups.com
thank you for the answer. I am not unfortunately a python guy and have to modify some fragment of code.. 
Reply all
Reply to author
Forward
0 new messages