| Reply | « Previous Thread | Next Thread » |
|
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: mobile webcam 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 !! 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:
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." )
|
|
I've heard there is probs with http post when using wap gateway.
|
| simo.salminen |
| View Public Profile |
| Find all posts by simo.salminen |
|
is there a workaround?
|
|
Use "normal" internet access point.What kind of access points name you have in the selection dialog?
|
| simo.salminen |
| View Public Profile |
| Find all posts by simo.salminen |
|
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 ( meet my dog ! ).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 ![]()
Last edited by MrKikkeli : 2006-03-17 at 00:45.
|
|
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! ![]() |
|
rexwal, the original post has the code (post_image method).
|
| simo.salminen |
| View Public Profile |
| Find all posts by simo.salminen |
|
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. http://aymanshamma.googlepages.com/h...frompys60tophp Includes all the py sample code as well as the php scripts to accept the requests. -a. |
|
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.
|
|
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 ![]() |
|
hello ,
mobil lenine code ? Could you show me the link to get it ? Is it available to public ? pys60 1.4.5,1.9.7,pygame,PyS60 CE on E90 , N810 with Python 2.5.2 and ... last PyS60 1.9.7 with touch ui on 5800 ! pys60 extension modules on http://cyke64.googlepages.com/ |
|
aymanshamma, nice tutorial. Additional tip: it is good to use multipart/form-data because (usually) server allows to upload bigger files with that method.
|
| simo.salminen |
| View Public Profile |
| Find all posts by simo.salminen |
|
Thanks simo -- I'll add your tip to my little website.
Cheers, -a. |
|
http://www.mobilenin.com/pys60/menu.htm <- link to mobile lenin code
|
|
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:
http://mattsstuff.free.fr/dotclear/i...1-mobilewebcam I hope it'll be useful, or that at least you can have as much fun with this as I have ![]() |
| Reply | « Previous Thread | Next Thread » |
| Thread Tools | Search this Thread |
|---|---|
| Rate This Thread | |
| Thread | Thread Starter | Forum | Replies | Last Post |
|---|---|---|---|---|
| Where can I upload an Appication? | Borriez | General Discussion | 0 | 2005-09-20 16:36 |
| Upload Image Problem!!! | ckeddie | General Browsing | 4 | 2005-01-26 07:58 |
| upload J2ME app onto Java phones | mzichao | Mobile Java General | 1 | 2005-01-11 08:11 |
| Linux driver in RedHat 7.3 | nsolhjoo | Multimodecards | 0 | 2003-10-24 18:04 |
| image upload incomplete | SkyRaVeR | Digital Rights Management & Content Downloading | 0 | 2003-06-02 23:48 |