You Are Here:

Community: Developer Discussion Boards

Reply « Previous Thread | Next Thread »

#1 Old image upload - 2007-02-07, 10:31

Join Date: Aug 2004
Posts: 146
krtrivdi's Avatar
krtrivdi
Offline
Forum Nokia Champion
Dear All

I have tried the mobilenin code for uploading an image to URL as per his example .It works great while uploading to image to mobilenin site. but when i tried to upload on my site it gives some forbidden 403 and sometime some eror 503. when i checked to error log on server it showed no such directory(actually directories are there which i have written in my python code) and the second error is of gnuncompress(): error...what is this? can anyone help me.


||Kiran ||
Nokia E-65
Nokia 7610
Nokia N95 8GB
Nokia E90
Nokia 5110 !!
Nokia 6110i !!
Reply With Quote

#2 Old Re: image upload - 2007-02-07, 12:12

Join Date: May 2006
Posts: 622
Location: Oulu, Finland
lfd
Offline
Super Contributor
Hi

Quote:
gnuncompress(): error...
Means that zlib module isn't loaded on your server. Ask your admin

Quote:
when i checked to error log on server it showed no such directory
In Jurgen's example, it uses a beijing directory. So it needs to be present(with enough rights to write inside) in the same directory than the PHP script.

LFD


Devices:
Nokia E61 3rd Edition - pys60 1.4.0

Tips and modules:
http://www.lfdm.net/thesis
Reply With Quote

#3 Old Re: image upload - 2007-02-07, 12:15

Join Date: Aug 2004
Posts: 146
krtrivdi's Avatar
krtrivdi
Offline
Forum Nokia Champion
Dear LFD

thanks for your quick reply. i have added required MIME types for gzip and ya i have created same path and directories like beijing, php, etc on my server too..i

what to do yaar?

kiran


||Kiran ||
Nokia E-65
Nokia 7610
Nokia N95 8GB
Nokia E90
Nokia 5110 !!
Nokia 6110i !!
Reply With Quote

#4 Old Wink Re: image upload - 2007-02-09, 10:11

Join Date: Feb 2007
Posts: 4
elbarto Simpsons
Offline
Registered User
Dear all,

When I enter the Images Directory, I got the following error:

IOError:[Error13] Permission denied: 'e:/Images'

Anyone? Thx.
Reply With Quote

#5 Old Re: image upload - 2007-02-09, 11:03

Join Date: May 2006
Posts: 622
Location: Oulu, Finland
lfd
Offline
Super Contributor
Hi elbarto Simpsons and welcome to the forum

Quote:
IOError:[Error13] Permission denied: 'e:/Images'
Try 'e:\\Images'

LFD


Devices:
Nokia E61 3rd Edition - pys60 1.4.0

Tips and modules:
http://www.lfdm.net/thesis
Reply With Quote

#6 Old Thumbs up Re: image upload - 2007-02-09, 12:45

Join Date: May 2006
Posts: 622
Location: Oulu, Finland
lfd
Offline
Super Contributor
Hi folks,

Since it is not the first time one ask for help with image upload I made a python and server script for you. So far it has worked everywhere I tried it. My method is different than Jurgen's. I use base64 encoding instead of zlib.

You can find it at http://students.oamk.fi/~dlefevre/th...d-image-to-url

B.R

LFD


Devices:
Nokia E61 3rd Edition - pys60 1.4.0

Tips and modules:
http://www.lfdm.net/thesis
Reply With Quote

#7 Old Re: image upload - 2007-02-10, 11:23

Join Date: Aug 2004
Posts: 146
krtrivdi's Avatar
krtrivdi
Offline
Forum Nokia Champion
Dear LFD

Thanks a million for your kind and instant support. I wish you next Forum Nokia champion form this stage .....You are great man!

I am really happy to have a person like you in the forum...

Thanks again ...it really works on any server...

Kiran


||Kiran ||
Nokia E-65
Nokia 7610
Nokia N95 8GB
Nokia E90
Nokia 5110 !!
Nokia 6110i !!
Reply With Quote

#8 Old Thumbs up Re: image upload - 2007-02-10, 18:34

Join Date: Feb 2007
Posts: 4
elbarto Simpsons
Offline
Registered User
Quote:
Originally Posted by lfd
Hi elbarto Simpsons and welcome to the forum

Try 'e:\\Images'

LFD
Dear LFD,

e:/ or e:\\ got the same error .. Any clue

I am new to deal with 'path' in such...
Reply With Quote

#9 Old Talking Re: image upload - 2007-02-10, 18:45

Join Date: Feb 2007
Posts: 4
elbarto Simpsons
Offline
Registered User
Quote:
Originally Posted by lfd
Hi folks,

Since it is not the first time one ask for help with image upload I made a python and server script for you. So far it has worked everywhere I tried it. My method is different than Jurgen's. I use base64 encoding instead of zlib.

You can find it at http://students.oamk.fi/~dlefevre/th...d-image-to-url

B.R

LFD
Work fine with my apache.
base64, zlib compression, u bet.


N73 - 1st Symbian
OS X user
Reply With Quote

#10 Old Re: image upload - 2007-02-12, 20:28

Join Date: Feb 2007
Posts: 4
elbarto Simpsons
Offline
Registered User
Quote:
Originally Posted by lfd
Hi folks,

Since it is not the first time one ask for help with image upload I made a python and server script for you. So far it has worked everywhere I tried it. My method is different than Jurgen's. I use base64 encoding instead of zlib.

You can find it at http://students.oamk.fi/~dlefevre/th...d-image-to-url

B.R

LFD
Dear LFD,
It work fine with a picture size under 100k, but it does not work with picture with the size over 500K, any idea?


N73 - 1st Symbian
OS X user
Reply With Quote

#11 Old Re: image upload - 2007-02-12, 21:35

Join Date: May 2006
Posts: 622
Location: Oulu, Finland
lfd
Offline
Super Contributor
Hi elbarto Simpsons,

You might have limitations on your server.

Running the same script on my desktop machine I managed to upload a 5Mb mp3 file to my server. I have don't a S60 phone with me tonight to confirm but it should be the same since it's only Python.

LFD


Devices:
Nokia E61 3rd Edition - pys60 1.4.0

Tips and modules:
http://www.lfdm.net/thesis
Reply With Quote

#12 Old Re: image upload - 2007-02-13, 21:15

Join Date: Sep 2005
Posts: 314
Location: Finland, Helsinki
aaaaapo
Offline
Regular Contributor
Quote:
Originally Posted by lfd
You might have limitations on your server. Running the same script on my desktop machine I managed to upload a 5Mb mp3 file to my server.
It might be a limitation in pys60 too: python2.2 in desktop (linux 2.6) seems to POST happily 7.5 megabytes (8 MB is too much).

Same method in 6630 fails if POST size is 30 kB.

Here is the function (simplified version):
Code:
    def _send_request(self, operation, params):
        """
        Send HTTP-request to the server using httplib.
        """
        params['rpc_op'] = operation
        params = urllib.urlencode(params)
        headers = {"Content-type": "application/x-www-form-urlencoded",
                   "User-Agent": self.ua,
                   }
        conn = httplib.HTTPConnection(self.host)
        conn.request("POST", self.script, params, headers)
        response = conn.getresponse()
        data = response.read()
        conn.close()
        return data
I have to do more tests. Perhaps the right answer is to use multipart/form-data.
Reply With Quote

#13 Old Re: image upload - 2007-02-14, 17:51

Join Date: Oct 2006
Posts: 24
andersnc
Offline
Registered User
Quote:
Originally Posted by aaaaapo
I have to do more tests. Perhaps the right answer is to use multipart/form-data.
I wrote a Flickr uploader for 3rd edition PyS60 devices (Teemu's Fupper and all the other similar applications that I found are for 2nd edition) and that's how I did all the image uploading. I think the largest file I moved off my phone was around a 1 MB and it never had any problems.

I got the code (below) from uploadr, but that author cites it originally coming from here: http://www.voidspace.org.uk/atlantib...thonutils.html. I can't find where specifically on this site it came from, but there's a lot of modules. I'll just post the two functions below and if there's more questions about them, I can provide some more code or poke about on that voidspace site some more.

Code:
    def build_request(self, theurl, fields, files, txheaders=None):
        """
        Given the fields to set and the files to encode it returns a fully formed urllib2.Request object.
        You can optionally pass in additional headers to encode into the opject. (Content-type and Content-length will be overridden if they are set).
        fields is a sequence of (name, value) elements for regular form fields - or a dictionary.
        files is a sequence of (name, filename, value) elements for data to be uploaded as files.    
        """
        content_type, body = self.encode_multipart_formdata(fields, files)
        if not txheaders: txheaders = {}
        txheaders['Content-type'] = content_type
        txheaders['Content-length'] = str(len(body))

        return urllib2.Request(theurl, body, txheaders)     

    def encode_multipart_formdata(self,fields, files, BOUNDARY = '-----192.168.1.110.501.356.1163842081.537.1-----'):
        """ Encodes fields and files for uploading.
        fields is a sequence of (name, value) elements for regular form fields - or a dictionary.
        files is a sequence of (name, filename, value) elements for data to be uploaded as files.
        Return (content_type, body) ready for urllib2.Request instance
        You can optionally pass in a boundary string to use or we'll let mimetools provide one.
        """    
        CRLF = '\r\n'
        L = []
        if isinstance(fields, dict):
            fields = fields.items()
        for (key, value) in fields:   
            L.append('--' + BOUNDARY)
            L.append('Content-Disposition: form-data; name="%s"' % key)
            L.append('')
            L.append(value)
        for (key, filename, value) in files:
            filetype = 'application/octet-stream'
            L.append('--' + BOUNDARY)
            L.append('Content-Disposition: form-data; name="%s"; filename="%s"' % (key, filename))
            L.append('Content-Type: %s' % filetype)
            L.append('')
            L.append(value)
        L.append('--' + BOUNDARY + '--')
        L.append('')
        body = CRLF.join(L)
        content_type = 'multipart/form-data; boundary=%s' % BOUNDARY        # XXX what if no files are encoded
        return content_type, body
Reply With Quote

#14 Old Re: image upload - 2007-02-15, 05:55

Join Date: Sep 2005
Posts: 314
Location: Finland, Helsinki
aaaaapo
Offline
Regular Contributor
Quote:
Originally Posted by andersnc
I wrote a Flickr uploader - -. I think the largest file I moved off my phone was around a 1 MB and it never had any problems.
Yes, multipart/form-data works fine up to 2 MB or something (tested in N70).

But in my example where
Content-type: application/x-www-form-urlencoded
and
params = urllib.urlencode(params)
request fails if the the size of params (in bytes) exceeds about 20-30kB.

Here is the end of the traceback. AssertionError?
Code:
result, rinfo = self._send_request(self.rpc_name(), params)
File "C:\System\Apps\PlokIn\Comm.py", line 136, in _send_request
data = response.read()
File "E:\system\libs\httplib.py", line 238, in read
s = self.fp.read()
File "E:\system\libs\httplib.py", line 794, in read
assert not self._line_consumed and self._line_left
AssertionError
Currently I don't have time to examine what raises this error, I'll change the code to use _send_multipart_request().
Reply With Quote

#15 Old Re: image upload - 2007-02-15, 16:45

Join Date: May 2006
Posts: 622
Location: Oulu, Finland
lfd
Offline
Super Contributor
Hi fellows,

It just came to my mind that I actually used already multipart/form-data upload with a different project.

I found a library HTTPFileUploader long time ago and I'm sorry that I can't tell you who wrote it. So here comes a good library to add in your tool box.

Download it HTTPFileUploader.txt and rename HTTPFileUploader.txt to HTTPFileUploader.py. Then simply push it on your phone and install it as a library (2nd edition) or create an installation package with ensymble to simplify the task (3rd edition)

Usage:
Code:
import os
from HTTPFileUploader import * # uploader class
 
# path of the file to download
filePath = "001.jpg"
 
# new HTTPFileUploader instance
uploader = HTTPFileUploader('yourServer.xxx', port = 80) # port optional if 80
 
# set page
uploader.setPage('/uploaderFolder/file_uploader.php')
 
# Add fields in HTTP: ex file name for or past example
uploader.setField("fileName", os.path.split(filePath)[1])
 
# upload file - returns True or False.
if not uploader.uploadFile(filePath, "picture"):
    print uploader.getResult()
And a php source for the server
PHP Code:
<?php
# Copyright (c) 2007 LEFEVRE Damien
# file_uploader.php implementation

// In this example a directory "images" needs to be present on the same directory where
// image_uploader.php is, with the necessary rights for the script to write data inside
$content_dir 'images/';
$filename Null;

if(isset(
$_POST['fileName'])){
    
$filename $_POST['fileName'];
}

if(isset(
$_FILES['picture'])){
    if (
$filename == Null){
        
$filename $_FILES['picture']['name'];
    }
    if( !
move_uploaded_file($_FILES['picture']['tmp_name'], $content_dir $filename) ){
        exit(
"Couldn't write the file in $content_dir");
    }
}
else{
    
// something when wrong
    
exit("False");
}
// return
echo "True";
?>
After, it is up to you to hack that codes to make them do what you want. I also added a note on my page http://lfdm.net/thesis/index.php/Code-snippets

LFD


Devices:
Nokia E61 3rd Edition - pys60 1.4.0

Tips and modules:
http://www.lfdm.net/thesis
Reply With Quote
Reply « Previous Thread | Next Thread »
Display Modes
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules

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

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump
Similar Threads
Thread Thread Starter Forum Replies Last Post
Opening a JPEG Image ummarbhutta Mobile Java Media (Graphics & Sounds) 8 2007-02-15 07:34
how to cut some part of Image mshouab Mobile Java Media (Graphics & Sounds) 2 2006-08-04 10:05
HELP: Mutable Image to Immutable Image? rj_cybersilver Mobile Java Media (Graphics & Sounds) 1 2005-03-26 10:58
Upload Image Problem!!! ckeddie General Browsing 4 2005-01-26 07:58
Nokia Image Converter davidpurdie General Discussion 0 2004-02-18 16:31

Rate This

 
Bookmark this page: DeliciousDiggFacebookGoogleYahooStumbleUponRedditDiigoTechnocratiTwitter  Share this page Share this page Print this Page Print this page Invite a friend Invite a friend
京ICP备05048969号    Email Newsletters Press Terms & Conditions Privacy Policy Sitemap Contact Us © 2009 Nokia