473,804 Members | 2,184 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

HTTP POST uploading large files

I'm thinking about writing a script to upload videos to sites
like YouTube or Google Video, which is usually done by a HTTP
POST.

The problem is, that videos, by nature are rather big files,
however urllib2 wants it's Request objects being prepared
beforehand, which would mean to first load the whole file to
memory.

I looked into pycURL, knowing that cURL can POST send files
directily from the file system, however pycURL doesn't expose
the neccesary functions yet.

Am I just blind for some urllib2/httplib feature, or some other
library? Or do I really have to fiddle around with sockets
myself (I hope not...).

Thanks in advance

Wolfgang Draxinger
--
E-Mail address works, Jabber: he******@jabber .org, ICQ: 134682867

Jan 19 '08 #1
4 7368
En Sat, 19 Jan 2008 21:19:24 -0200, Wolfgang Draxinger
<wd********@dar kstargames.dees cribi�:
I'm thinking about writing a script to upload videos to sites
like YouTube or Google Video, which is usually done by a HTTP
POST.

The problem is, that videos, by nature are rather big files,
however urllib2 wants it's Request objects being prepared
beforehand, which would mean to first load the whole file to
memory.

I looked into pycURL, knowing that cURL can POST send files
directily from the file system, however pycURL doesn't expose
the neccesary functions yet.

Am I just blind for some urllib2/httplib feature, or some other
library? Or do I really have to fiddle around with sockets
myself (I hope not...).
I'm afraid urllib2 currently doesn't handle this. Neither the lower layer,
httplib. HTTPConnection should be upgraded to handle 'Transfer-Encoding:
chunked', by example. (Chunked responses are handled correctly, but a
request cannot be chunked)

A Q&D approach would be to patch httplib.HTTPCon nection.send, to accept a
file or file-like argument. Around line 707, instead of
self.sock.senda ll(str):

if hasattr(str, 'read'):
BUFSIZE = 4*1024
while True:
block = str.read(BUFSIZ E)
if not block: break
self.sock.senda ll(block)
else:
self.sock.senda ll(str)

and ensure the Content-Length header is already set, so no attempt is made
to compute len(str)

--
Gabriel Genellina

Jan 20 '08 #2
Wolfgang Draxinger wrote:
The problem is, that videos, by nature are rather big files,
however urllib2 wants it's Request objects being prepared
beforehand, which would mean to first load the whole file to memory.
Try using mmap. Here is some untested code:

map = mmap(file.filen o(), len(file), access=ACCESS_R EAD)
try:
data = mmap.read()
request = Request(url, data, headers)
...
finally:
map.close()
- Brian

Jan 20 '08 #3
Wolfgang Draxinger <wd********@dar kstargames.dewr ites:
Am I just blind for some urllib2/httplib feature, or some other
library? Or do I really have to fiddle around with sockets
myself (I hope not...).
I did something like that by just opening a socket and writing the
stuff with socket.sendall. It's only about 5 lines of code and it's
pretty straightforward .
Jan 20 '08 #4
Paul Rubin wrote:
Wolfgang Draxinger <wd********@dar kstargames.dewr ites:
>Am I just blind for some urllib2/httplib feature, or some
other library? Or do I really have to fiddle around with
sockets myself (I hope not...).

I did something like that by just opening a socket and writing
the
stuff with socket.sendall. It's only about 5 lines of code and
it's pretty straightforward .
Well, for YouTube you've to fiddle around with cookies,
form/multipart data and stuff like that. It's a bit more than
just opening a socket, there's some serious HTTP going on.

However I found a solution: The curl program, that comes with
libcurl and can be found on most *nix systems allows to do
pretty sophisticated HTTP requests, among them also sending
files by POST. So instead of using urllib2 or sockets from
Python, now my program just generates the appropriate calls to
curl, provides the in memory storage of cookies and does the
neccesary HTML parsing*.

Wolfgang Draxinger

*) YouTube uploads videos in a two part process: First you set
the various video options, in return you get a form with some
hidden input fields, some of them providing a handle to the
already sent video information. That data has to be extracted
from the form and be put into the POST that also transfers the
video file.

--
E-Mail address works, Jabber: he******@jabber .org, ICQ: 134682867

Jan 20 '08 #5

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

Similar topics

6
2832
by: Chamomile | last post by:
can anyone point me to some straightforward information on file uploading without using an html form? That is, direcly from within a php script. if I know the local path etc. to a particular requested file how can I send it directly to a location on a remote webserver following a request from the remote server? The motivation is that I have a large number of image files that are
5
2008
by: Chris Hughes | last post by:
I have an environment with many thousands of client machines uploading data files several times each day to a web server via HTTP PUT. To avoid disk I/O (for performance), I am implementing a HTTP handler to intercept and process incoming data without touching the disk. I cannot detect PUT requests with my handler (don't know if this is even supported), so I'm redirecting all requests to the handler as POST using an ISAPI filter. I...
3
1979
by: deko | last post by:
Newbie ASP.NET question: Now that I've created an ASP.NET site, how to I get it to my hosting provider? I've developed sites with Dreamweaver MX in the past - with Dreamweaver, it's very easy. The ability to link to the remote site (via FTP) is built into the IDE and all you have to do is click upload. Does Visual Studio have a similar feature? How do most people deploy their sites to a remote server from Visual Studio?
6
1540
by: tajeshwar | last post by:
Hi, I am using file post control to upload a large file to web server. this file can be very large(5-10 GB). Now what this control do is that it will reject any such request because of ASP.NET security features. Now what I want to do is to handle this thing at HttpModule level. That is see if the request is for uploading a file. If so then I should be able to change the content-length property in headers and make it small so that
2
2709
by: WSE with SSL and large amount of data | last post by:
Hi there, What's the better strategy for uploading large files trough webservices? I can use Dime/WS-Attachments but for files with over 5MB in size, maybe I got some timeout/refuse problems in my server. Is it a good idea upload the files in chucks? In this case, how can I control and validate the transfering, and ensure the security? As a matter of fact, I have to use standarts for EDI processes. Thanks in advanced.
16
4990
by: lawrence k | last post by:
I've a file upload script on my site. I just now used it to upload a small text document (10k). Everything worked fine. Then I tried to upload a 5.3 meg Quicktime video. Didn't work. I've set the POST limit in php.ini to 8 megs. What reasons, other than the POST limit, would a large upload fail?
5
3155
by: hecuba007 | last post by:
My apologies if this question has been asked before .. I would like to split large files into smaller chunks for uploading to php for re-assembly on the server. Is there a (relatively) simple way of doing this in javascript? If so, could someone point me to relevant documentation to read or (if really simple!) give me some coding hints? Thanks.
3
2527
by: Pavel Dvorkin | last post by:
Hi All, I have next problem. A page contains HtmlInputFile. User tries to upload file. File size is too large, so I can't allow this request. Now I have DNS error accoeding to MSDN When uploading large files, use the maxRequestLength attribute of the
10
8105
by: =?Utf-8?B?RGFu?= | last post by:
I'm using a pure ASP upload script to handle file uploading. We run IIS6 and I'm aware of the AspMaxRequestEntityAllowed variable in the metabase. I upped this to allow the file size maximum and it was working for the past couple months. Now all of a sudden in the past couple of days we are seeming to have problems. The upload works fine for anything up to around 2mb (or so it seems). When uploading about 20mb worth (10x2mb files), I...
0
10595
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
10343
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
7634
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
6862
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
5530
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5673
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4308
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
3831
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3001
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.