Brian D
Brian D

Reputation: 10133

Converting raw binary data into an image file?

I'm trying to read a field from an Active Directory entry which contains raw jpeg binary data. I'd like to read that data and convert it to an image file for use in my django-based application. I cannot for the life of me figure out how to handle this data in a nice way. Any ideas?

Edit:

To anyone who might come across this in the future: there's a method in python's OS library:

os.tmpfile()

it creates a file and destroys it once the file descriptor is closed. Very useful for this situation.

Upvotes: 0

Views: 3946

Answers (1)

Here is somebody who was having the same problem -- check out the latest post at the bottom. http://groups.google.com/group/django-users/browse_thread/thread/4214db6699863ded/5d816b02daca3186

Looks like passing raw data to SimpleUploadedFile is what you are looking for.

request._raw_post_data

The raw HTTP POST data as a byte string. This is useful for processing data in different formats than of conventional HTML forms: binary images, XML payload etc.

http://docs.djangoproject.com/en/dev/ref/request-response/#httprequest-objects

I know this isn't part of the question, but this looks pretty awesome! "HttpRequest.read() file-like interface" http://docs.djangoproject.com/en/dev/ref/request-response/#django.http.HttpRequest.read

Upvotes: 1

Related Questions