×

Discussion Board

Results 1 to 15 of 15

Hybrid View

  1. #1
    Registered User
    Join Date
    Mar 2006
    Posts
    29

    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:
    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)
    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." )
    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.

  2. #2
    Regular Contributor
    Join Date
    Aug 2004
    Posts
    295

    Re: incomplete upload

    I've heard there is probs with http post when using wap gateway.

  3. #3
    Registered User
    Join Date
    Mar 2006
    Posts
    29

    Re: incomplete upload

    is there a workaround?

  4. #4
    Regular Contributor
    Join Date
    Aug 2004
    Posts
    295

    Re: incomplete upload

    Use "normal" internet access point.What kind of access points name you have in the selection dialog?

  5. #5
    Registered User
    Join Date
    Mar 2006
    Posts
    29

    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 ( 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-16 at 23:45.

  6. #6
    Regular Contributor
    Join Date
    Nov 2004
    Posts
    105

    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!

  7. #7
    Regular Contributor
    Join Date
    Aug 2004
    Posts
    295

    Re: incomplete upload

    rexwal, the original post has the code (post_image method).

  8. #8
    Registered User
    Join Date
    Feb 2006
    Posts
    23

    Post 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.

    http://aymanshamma.googlepages.com/h...frompys60tophp

    Includes all the py sample code as well as the php scripts to accept the requests.

    -a.

  9. #9
    Registered User
    Join Date
    Mar 2006
    Posts
    29

    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.

  10. #10
    Regular Contributor
    Join Date
    Nov 2004
    Posts
    105

    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

  11. #11
    Registered User
    Join Date
    Feb 2005
    Location
    Belgium (Europe)
    Posts
    1,352

    Re: incomplete upload

    hello ,

    mobil lenine code ? Could you show me the link to get it ?
    Is it available to public ?
    pys60 1.4.5 and 2.0.0, pygame, PyS60 CE on E90 and 5800 !

    Find my pys60 extension modules on cyke64.googlepages.com

  12. #12
    Regular Contributor
    Join Date
    Aug 2004
    Posts
    295

    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.

  13. #13
    Registered User
    Join Date
    Feb 2006
    Posts
    23

    Smile Re: incomplete upload

    Thanks simo -- I'll add your tip to my little website.

    Cheers,

    -a.

  14. #14
    Regular Contributor
    Join Date
    Nov 2004
    Posts
    105

    Re: incomplete upload

    http://www.mobilenin.com/pys60/menu.htm <- link to mobile lenin code

  15. #15
    Registered User
    Join Date
    Mar 2006
    Posts
    29

    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:
    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

Similar Threads

  1. Where can I upload an Appication?
    By Borriez in forum General Development Questions
    Replies: 0
    Last Post: 2005-09-20, 15:36
  2. upload J2ME app onto Java phones
    By mzichao in forum Mobile Java General
    Replies: 1
    Last Post: 2005-01-11, 07:11
  3. Linux driver in RedHat 7.3
    By nsolhjoo in forum Multimodecards
    Replies: 0
    Last Post: 2003-10-24, 17:04
  4. image upload incomplete
    By SkyRaVeR in forum Digital Rights Management & Content Downloading
    Replies: 0
    Last Post: 2003-06-02, 22:48

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×