Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries. Thanks for all your past and future contributions.

Archived:How to upload a file to server with application/x-www-form-urlencoded

From Wiki
Jump to: navigation, search

Archived.pngAquivado: Este artigo foi arquivado, pois o conteúdo não é mais considerado relevante para se criar soluções comerciais atuais. Se você achar que este artigo ainda é importante, inclua o template {{ForArchiveReview|escreva a sua justificativa}}.

All PySymbian articles have been archived. PySymbian is no longer maintained by Nokia and is not guaranteed to work on more recent Symbian devices. It is not possible to submit apps to Nokia Store.

Article Metadata
Created: lfd (14 May 2007)
Last edited: hamishwillee (31 May 2013)

It is simple to upload a file using application/x-www-form-urlencoded combined with base64. The only problem is that the uploading fails with files exceeding few 10th Kb.

Client source:

import httplib, urllib
import os.path
def imageToURL( aPath ):
# read the binary data of the picture
data = open(aPath, 'rb').read()
# encoded it to base64
encodedData = data.encode( 'base64' )
headers = { "Content-type": "application/x-www-form-urlencoded",
"Accept": "text/plain",
params = urllib.urlencode({ u'fileName': os.path.split(aPath)[1],
conn = httplib.HTTPConnection( "" )
conn.request( "POST", "/uploaderFolder/image_uploader.php", params, headers )
response = conn.getresponse( )
# returns "True" or "False" if failed
print )
# status for debugging
print response.status
conn.close( )
if __name__ == "__main__":

Server source (image_uploader.php):

// 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
$filename = $_POST['fileName'];
// if not: just stop here
print "False";
$encodedData = $_POST['data'];
$data = base64_decode($encodedData);
// if not: just stop here
print "False";
// full path for the image
$filepathname = 'images/'.$filename;
// write the file to the server into the images directory
$handle = fopen($filepathname, 'wb');
fputs($handle, $data, strlen($data));
// return
echo "True";
This page was last modified on 31 May 2013, at 01:05.
112 page views in the last 30 days.