473,699 Members | 2,311 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

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.FieldStorag e()
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_conten ts("php://input");
fwrite($file_ha ndle, $mydata);
fclose($file_ha ndle);

What I need is a Python equivalent of the the above PHP script. The
content-type in the POST header is currently set to
"applicatio n/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

Nov 22 '06 #1
1 2379
At Wednesday 22/11/2006 09:08, st****@microsof t.com 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.FieldStorag e()
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_conten ts("php://input");
fwrite($file_h andle, $mydata);
fclose($file_h andle);

What I need is a Python equivalent of the the above PHP script. The
content-type in the POST header is currently set to
"applicatio n/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.FieldStorag e()
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
Nov 24 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
821
by: Beatrice | last post by:
I am stuck with this problem and desperately need your help. I would like to upload an xml file or any file from client machine and then save it to the server machine. Since the file path on the client machine is predefined within the program, I am using the HTMLInputFile control, postedfile, saveas ... and set the input control visibility to hidden. However, the control value is read only and there is no way I can set the client file...
3
1739
by: Rob Nicholson | last post by:
The following code added to Page_Load works a treat: Response.ContentType = "application/zip" Response.AppendHeader("Content-Disposition", "attachment; filename=DesktopChange.pdf") Response.WriteFile("C:\Inetpub\wwwroot\Download\DesktopChange.pdf") Response.Flush() But *only* if the document exists in the web site or is accessible by the ASPNET account. However, it fails if the document is stored on the network,
9
2413
by: CGW | last post by:
I asked the question yesterday, but know better how to ask it, today: I'm trying to use the File.Copy method to copy a file from a client to server (.Net web app under IIS ). It looks to me that when I give a path like @"C:\holdfiles\myfile.txt" it looks on the server C drive. How do I pull from the client? Do I need a different class and/or method? Filestream? -- Thanks,
22
6267
by: Jordan S. | last post by:
SQL Server will be used as the back-end database to a non trivial client application. In question is the choice of client application: I need to be able to speak intelligently about when one client (MS Access vs ..NET Windows Forms) would be preferred over the other. While I have some good arguments on both sides, I would appreciate your points of view on the topic.
6
2003
by: Simon Harvey | last post by:
Hi everyone, We have a need to make a Windows Forms (2.0) client application that will be installed on our clients site. The data that the application uses needs to be centrally available to a potentially large number of other sites, which would seem to leave us with our traditional approach, or having a central database server on a dedicated server someplace.
3
2796
by: Big Charles | last post by:
Hello, My ASP.NET application has to read a DBF file in a CD from CD-Drive of a client PC. Then, I have to pass the data to a DataReader. The route is: Client-PC -Server The DBF file could be between 20MB - 40MB, which is quite large. If the ASP.NET application has to upload the file, then I would have to change in the web.config this value: <httpRuntime maxRequestLength="4096" and instead of 4096, put
10
2431
by: eggie5 | last post by:
Is it possible to get a file without using a form post? I want to get the data (bytes) of a file, text or binary, and just save it to a variable. Similar to the post body of a form that has a file input element in it. Ultimately what I want to do is get a file off client machine (that they specify) and send it to the server using a standard post request. This is exactly the same as a form post with an file input element, but I don't...
2
1506
by: minhtran | last post by:
HI all I wish to get help from anyone as how can I upload a file as Excel file or Text from Client side to Webserver then we can read the file in ASP.NET or any code can read the file from client. Please, help me if you have any idea . Thank you so much in advance.
1
2820
by: Reemajain | last post by:
Hi All, I want to upload a text file from client local machine in my ASP.NET application without user intervantion ,file is at predefined location.....If there is any way to get it through javascript or ajax please let me know Thanks
0
8685
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9172
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9032
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
6532
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5869
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4626
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3054
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2344
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2008
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.