I have Arduino sending me chunks of a picture in a series of http post requests. They arrive at server in unicode format. I convert them to utf8 and then bson.binary.Binary in order to store in mongo db. Later I want to reassemble the image and show it inside img tag on a web page. What would be the right way to do it (at least to assemble it back into an image through writing to a file)?
Asked
Active
Viewed 235 times
0
-
The proper way would be to use [GridFS](http://docs.mongodb.org/manual/core/gridfs/) and have MongoDB do it for you. – Markus W Mahlberg Nov 22 '14 at 15:41
-
Thanks but I don't have a problem with the image chunk size rather assembly. – jump3r Nov 22 '14 at 16:10
-
You might want to read before assuming. The image will be assembled for you. – Markus W Mahlberg Nov 22 '14 at 17:24
-
@MarkusWMahlberg You might want to read the question. The chunks are made on the Arduino. – UncleO Nov 22 '14 at 18:14
-
It is stored in MongoDB. No one prevents storing them in GridFS after all chunks are sent. – Markus W Mahlberg Nov 22 '14 at 19:32
-
@MarkusWMahlberg Agreed, GridFS can be used. But there is no point in using it, because the chunks are already small, as jump3r said some time ago. – UncleO Nov 22 '14 at 19:38
-
You should provide more context in your question. What kind of image? png? How are you chunking the image on the Arduino? Why unicode? How does the server know which packets go together? and in which order? (metadata for the chunks) – UncleO Nov 22 '14 at 19:42
-
@UncleO: Dealing with it afterwards becomes easier. A simple query, and no assembly logic to maintain. All this for collecting the chunks _one time_, eliminating the need of assembling them manually _for each request_. – Markus W Mahlberg Nov 22 '14 at 19:49
-
Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/65441/discussion-between-uncleo-and-markus-w-mahlberg). – UncleO Nov 22 '14 at 19:51
1 Answers
0
For a start, get Unicode out of the algorithm. Unicode is for text data, and unless your image data is in a very surprising format, it is a stream of arbitrary binary octets. Consider using application/octet-stream
in your HTTP request, and storing the data as byte strings instead of Unicode strings. See examples at How to send binary post data via HTTP? and Python HTTP POST binary file upload with pycurl (Python recipe) .

Community
- 1
- 1

Jim DeLaHunt
- 10,960
- 3
- 45
- 74