Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > File upload from client application (non-form based upload)

Reply
Thread Tools

File upload from client application (non-form based upload)

 
 
stuart@microsoft.com
Guest
Posts: n/a
 
      11-22-2006
Hi

I'm trying to write a Python script to receive and save a file on a web
server that has been POST'ed from a client application.

In essence, this is similar to handling a file upload from an HTML
form. However, I can't use:

form = cgi.FieldStorage()
fileitem = form['file']

since the file is not coming from a form, and hence I don't have a form
field called 'file'.

I have working server-side code in PHP to do this (error handling
removed):

$file = "./test.jpg";
$file_handle = fopen($file,"w");
$mydata = file_get_contents("php://input");
fwrite($file_handle, $mydata);
fclose($file_handle);

What I need is a Python equivalent of the the above PHP script. The
content-type in the POST header is currently set to
"application/octet-stream" which works fine with the php code above.

Any help, advise, pointers, sample code would be hugely welcome,

Many thanks in advance,

Stuart

 
Reply With Quote
 
 
 
 
Gabriel Genellina
Guest
Posts: n/a
 
      11-25-2006
At Wednesday 22/11/2006 09:08, wrote:

>I'm trying to write a Python script to receive and save a file on a web
>server that has been POST'ed from a client application.
>
>In essence, this is similar to handling a file upload from an HTML
>form. However, I can't use:
>
>form = cgi.FieldStorage()
>fileitem = form['file']
>
>since the file is not coming from a form, and hence I don't have a form
>field called 'file'.
>
>I have working server-side code in PHP to do this (error handling
>removed):
>
>$file = "./test.jpg";
>$file_handle = fopen($file,"w");
>$mydata = file_get_contents("php://input");
>fwrite($file_handle, $mydata);
>fclose($file_handle);
>
>What I need is a Python equivalent of the the above PHP script. The
>content-type in the POST header is currently set to
>"application/octet-stream" which works fine with the php code above.


You got rather close... "file" is not an item, it's an attribute, a
file-like object already open:

form = cgi.FieldStorage()
fileitem = form.file
data = fileitem.read()


--
Gabriel Genellina
Softlab SRL

__________________________________________________
Correo Yahoo!
Espacio para todos tus mensajes, antivirus y antispam ˇgratis!
ˇAbrí tu cuenta ya! - http://correo.yahoo.com.ar
 
Reply With Quote
 
 
 
Reply

Thread Tools

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Upload a file without file Upload control - ASP.Net =?Utf-8?B?U2FyYXY=?= ASP .Net 3 08-03-2005 01:09 AM
Web-based file upload help Chris Milliken ASP .Net 2 05-04-2005 06:43 PM
Question: Writing text file based TestBenches vs. Waveform file based simulation. BLF VHDL 4 08-07-2004 12:44 AM
How to detect sizeof upload in order to show status of browser file upload? Heather Fraser Java 0 07-05-2004 12:35 AM
Upload Excel with Macros using HTML File Upload Prakash ASP General 3 11-12-2003 04:26 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57