Transfer large files using HTTP/POST - c

How can I upload (very) large file with HTTP protocol in C (or C++)?
I know it's not the right way to upload huge files, but that's not the point.
I've already seen sources about POST transfers of files in C++ but I noticed that, each time, the WHOLE binary file was included inside the POST sequence (between "--boundary").
So, before going deeper and deeper into Webkit/Gecko source code, does somebody know how do they do?

You may use "Content-Range" header in HTTP POST request, to upload a slice of a huge file.
POST http://[server_ip]:80/upload?fn=xx.dat HTTP/1.1
Content-Range: bytes=0-4095
Content-Type: application/octet-stream
Content-Length: 4096
......

You can use chunking method to send the data in chunks. This will allow you to send/receive data on a larger scale. Refer to RFC 2616 on how chunking really works.

Related

Why is downloading a file of unknown size so rare these days?

Does anyone remember around 10-12 years ago, downloading files (game demos etc) from web servers often used to be very frustrating because Internet Explorer (I was young and naive) sometimes didnt tell you the size of the file you were downloading. This could lead to frustrating waits because sometimes the web page didn't tell you the file size either! The download just ticked a long, it used to say "1.2meg download of unknown" or similar, and eventually it would magically complete! (If you modem didn't cut off before then)
Why does this not happen anymore? What has changed and how?
HTTP servers typically supply a "Content-Length" response header when serving files, which didn't always used to be the case. Even when it's not a static file being served, developers are gradually becoming more aware of the importance of setting HTTP headers correctly to work with HTTP proxies etc.
It also used to be that a major reason for using FTP instead of HTTP was to be able to restart downloads-- the Range/Content-Range headers have eliminated that, too.

App Engine: Is it possible to disable Transfer-Encoding: Chunked for large static files?

As a follow-up to this question, is it possible to disable the "Transfer-Encoding: Chunked" method for large static files, therefore forcing a Content-Length to be returned instead?
My site serves a few Flash files. The small ones (500-700kb) report a Content-Length fine, but the large one (approx 3MB) doesn't, instead using chunked mode.
Although the file downloads fine, the Flash preloader doesn't work, because it can't tell how long the file is, and therefore what percentage is loaded.
Is my only option to write a dynamic handler to serve the static file?
Thanks.
Transfer-Encoding is in the list of Disallowed HTTP Response Headers (modifying them has no effect). source

Sending SOAP requests using libcurl as XML file

I'm trying to use libcurl to do a SOAP http post to a web service. I have the SOAP requests already formed in XML files which I generate. Now I need to transefer these XML files to the webservice. N.B. I'm pretty new to writing webservices (especially in C).
Is there a way do send the SOAP requests straight from the XML file using libcurl? Or do I have to read the contents into a string? I'm restricted to using the C programming language to complete the task.
I've been looking through documentation and different code snippets but I can't seem to locate anything to do the requested. This curl link does it through a string http://curl.haxx.se/libcurl/c/post-callback.html). FOr speed purposes I would greatly prefer to not have to pass to a string before sending it.
you use curl_easy_setopt()? then you may want to take a look at CURLOP_WRITEFUNCTION and CURLOPT_WRITEDATA.
The way I do this:
* Get TinyXML, load the file into a TiXmlDocument and use the TiXmlPrinter to get the XML file as string
* Set the value of the string in the body of the post request( also, set headers, but they are the same as HTTP standard headers)
* Take a look at curl_easy_setopt() for callback and other stuff (:
Good Luck (:

What HTTP header is needed to be returned so web browsers use the suggested filename? (File download from CGI in C)

We have a PDF file download link on a web page with a C language CGI program actually passing on the file from our embedded device's web server. The web server is custom coded because of severe memory limitations.
The suggested filename by the C program is "Manual.pdf".
On Internet Explorer 8, when we click on the link the usual "Open/Save" box opens with the suggested filename displayed being "download.pdf" which is wrong. On Firefox, the suggested filename is "download.cgi" which is worse. However both browsers correctly indicate that the download is a PDF type.
Here are a few unrelated snippets of code to show the headers we are returning:
{ CONTENT_TYPE_PDF, "application/pdf\nContent-Disposition:attachment;" }
sprintf(tmpBuf, "Content-Type: %s\n", get_tbl_string((tbl_str_itm_t*)content_type, session->response.contenttype));
strcpy(tmpBuf, "filename=Manual.pdf\n");
strcat(tmpBuf, "Cache-Control: no-cache, no-store\n");
Can anyone tell what we are doing wrong?
Any help greatly appreciated.
Best regards,
Bert
The "filename" stuff is part of the content-disposition header.
Content-Disposition: attachment; filename=Manual.pdf header is good solution, however it doesn't work well if your filename has non-english characters. Another solution is to append "/Manual.pdf" path to your cgi script, i.e. use URLs like: http://server/path/my.cgi/Manual.pdf, and then your my.cgi program will be called with PATH_INFO=/Manual.pdf. For funky filenames, this works better than Content-Disposition header.
Update: If you are interested in browser support for Content-Disposition header, check http://greenbytes.de/tech/tc2231/.
Update: Another interesting article on the topic: Link
You might find some of the tips here useful:
http://blog.httpwatch.com/2010/03/24/four-tips-for-setting-up-http-file-downloads/

Reading ID3 tags of a remote mp3 file?

Read MP3 Tags with Silverlight got me started with reading id3 tags, but i realize that taglib# online deals with local file paths ?
Is there a way of reading this info from a remote file ?
I recently answered the same question for Ruby (see below) - I'm pretty sure you can do something similar.
The idea is:
use HTTP 1.1 protocol or higher, and a Range HTTP-request.
download the beginning section (100 bytes) of the ID3v2-tag
from the first few bytes downloaded, you can determine the correct length of the complete ID3v2 tag, e.g. N
download the first N bytes of the file (e.g. the complete ID3v2-tag)
parse the ID3v2 tag for your purposes
See:
Read ID3 Tags of Remote MP3 File in Ruby/Rails?
Tim Heuer has a good blog post on doing this. http://timheuer.com/blog/archive/2010/01/30/reading-mp3-id3-tags-with-silverlight-taglib.aspx
Like yourself, he also ran into the problem of TabLib# only using local paths.
One thing that TagLib# didn’t have was a stream input implementation. Most of the libraries, in fact, assumed a local file path. Luckily the library was written using a generic ‘File’ interface, so I just had to create my own StreamFileAbstraction. I chose to do this within my project rather than the base library. It was easy since the LocalFileAbstraction actually perfomed an Open on the file as it’s first task and set some public variables. My abstraction basically just hands the stream already and ready to go.
There is an example on the novell site that uses file abstraction.
http:// developer.novell.com/wiki/index.php/TagLib_Sharp:_Examples

Resources