-
incomplete upload
Hello all,
I am currently developping for fun a "mobile webcam" in python, ie basically I am uploading a picture every 60 seconds to a server.
So far everything goes well, excepted for the fact that the picture that I send seems to reach only partially my server.
As you can see:
[URL=http://pangcentury.free.fr/mobileWebcam/mobileWebcam.jpg]mobile webcam[/URL]
The jpeg file is incomplete most of the time.
I've tried my python code on my computer's interpreter ( I only had to remove the "pys60 only" part, mostly GUI ) and there's no problem with the upload.
Is there a problem with my phone ? ( a Nokia 6680 ) Or is it a problem with the ISP parameters ? is there a way I can check what's wrong for sure ? And most important, how can I fix it !! :D
here's the python code I use ( the most relevant parts according to me ):
[CODE]
def post_image(cell_id, key, nom_fichier, contenu):
BOUNDARY = '-------------UhUhUh------'
CRLF = '\r\n'
L = []
L.append('--' + BOUNDARY)
L.append('Content-Disposition: form-data; name="cellid"')
L.append('')
L.append(cell_id)
L.append('--' + BOUNDARY)
L.append('Content-Disposition: form-data; name="%s"; filename="%s"' % (key, nom_fichier))
L.append('Content-Type: image/jpeg')
L.append('')
L.append(contenu)
L.append( '--' + BOUNDARY + '--' )
L.append('')
body = CRLF.join(L)
content_type = 'multipart/form-data; boundary=%s' % BOUNDARY
conn = httplib.HTTPConnection("pangcentury.free.fr")
conn.putrequest('POST', '/mobileWebcam/mobileWebcam.php')
conn.putheader('content-type', content_type)
conn.putheader('content-length', str(len(body)))
conn.endheaders()
conn.send(body)[/CODE]
and
[CODE]
def run():
global running, img, total_bytes_sent, max_bytes, direction, white_bal, expos, fl, IMEI
while running and total_bytes_sent < max_bytes:
if int( sysinfo.battery() ) < 2:
logging(u"Attention, batterie trop faible !\nL'application va se terminer.")
running = 0
else:
params = { 'mode':'RGB16', 'size': (640,480),
'flash':fl, 'zoom':0, 'exposure': expos,
'white_balance':white_bal, 'position':0
}
img = apply(camera.take_photo, (), params)
img = img.resize((160,120), keepaspect = 1 )
if direction != '':
img = img.transpose(direction)
img.save("E:\\Images\\mobileWebcam.jpg")
cellid = location.gsm_location()[3]
cell_id = str(cellid)
taille = os.path.getsize("E:\\Images\\mobileWebcam.jpg")
fichier = open("E:\\Images\\mobileWebcam.jpg", 'rb')
try:
post_image(cell_id, 'image', 'nokia6680.jpg', fichier.read())
total_bytes_sent += int(taille)
truc = total_bytes_sent / 1024
truc2 = unicode(truc)
truc2 += u" ko envoyés au total"
logging(truc2)
countdown(60)
except:
logging(u"erreur dans l'envoi du fichier" )
running = 0
fichier.close()
if total_bytes_sent > max_bytes:
logging(u"maximum d'upload autorisé atteint." )
[/CODE]
Oh and while I am at it, here's a likely bug I stumbled upon while coding this: it seems like you can't use the flash in camera.take_photo() if the picture size is (160,120). That's why I have to take the picture first in (640,480) and resize it.
-
Re: incomplete upload
I've heard there is probs with http post when using wap gateway.
-
Re: incomplete upload
-
Re: incomplete upload
Use "normal" internet access point.What kind of access points name you have in the selection dialog?
-
Re: incomplete upload
Wap, Gprs and a third one the "nokia setting wizard" set up by himself. I haven't checked the details of this one yet.
so far, from my own experience, the wap access was the less reliable. GPRS was better, and now it seems that the 3rd one works okay, according to the last picture I uploaded ( [URL=http://pangcentury.free.fr/mobileWebcam/mobileWebcam.jpg]meet my dog ! ;)[/URL] ).
I'll try again tomorrow while hanging out in Paris and I'll keep you informed.
Edit : it doesn't seem to make a difference at all :(
-
Re: incomplete upload
Hi MrKikkeli! Can I just ask you a quick question if its possible? Just wondering how you manage to post an image from python to the web?
How do you manage to add the image data into the http request because that seems really really cool! :)
-
Re: incomplete upload
rexwal, the original post has the code (post_image method).
-
Re: incomplete upload
rexwal,
I have a small tutorial online on how to do HTTP Posts of text and binary data as well as multipart form data, from a PyS60 device via php/apache.
[url]http://aymanshamma.googlepages.com/httppostfrompys60tophp[/url]
Includes all the py sample code as well as the php scripts to accept the requests.
-a.
-
Re: incomplete upload
if you ever use my code or aymanshamma's code, I am very curious to hear about it, especially if you manage to receive complete pictures on the server side.
-
Re: incomplete upload
Well, I was doing something else completely.. and it did work :) .. I used part's of your code and mobile lenin's code.. it wasn't to do with sending over http, but over sockets to a j2me app running on the phone.. and it's working pretty well to date :)
-
Re: incomplete upload
hello ,
mobil lenine code ? Could you show me the link to get it ?
Is it available to public ?
-
Re: incomplete upload
aymanshamma, nice tutorial. Additional tip: it is good to use multipart/form-data because (usually) server allows to upload bigger files with that method.
-
Re: incomplete upload
Thanks simo -- I'll add your tip to my little website.
Cheers,
-a.
-
Re: incomplete upload
[url]http://www.mobilenin.com/pys60/menu.htm[/url] <- link to mobile lenin code
-
Re: incomplete upload
I am done with my "mobile Webcam": the code works, well at least does what I expect it to do, so I thought I'd share it with you:
[url]http://mattsstuff.free.fr/dotclear/index.php?2006/04/24/11-mobilewebcam[/url]
I hope it'll be useful, or that at least you can have as much fun with this as I have :)