Skip to content

Commit

Permalink
Merge pull request mozilla#14 from tarekziade/master
Browse files Browse the repository at this point in the history
using mimetypes to guess the mimetype of uploaded screenshots
  • Loading branch information
zalun committed Sep 20, 2012
2 parents 0138680 + 8e0b3ce commit b6ce526
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions python/lib/marketplace.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import logging
import time
import urllib
import mimetypes

from base64 import b64encode

Expand Down Expand Up @@ -240,10 +241,13 @@ def create_screenshot(self, app_id, filename, position=1):
s_content = s_file.read()
s_encoded = b64encode(s_content)
url = self.url('create_screenshot') % app_id
# TODO find the mimetype of the file
mimetype = 'image/jpg'

mtype, encoding = mimetypes.guess_type(filename)
if mtype is None:
mtype = 'image/jpeg'

data = {'position': position,
'file': {'type': mimetype,
'file': {'type': mtype,
'data': s_encoded}}
return self.post(url, data)

Expand Down

0 comments on commit b6ce526

Please sign in to comment.