Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ MT-multithreading and servers » HTTP Client and file upload
HTTP Client and file upload [message #18829] Sat, 25 October 2008 16:37 Go to next message
mdelfede is currently offline  mdelfede
Messages: 1307
Registered: September 2007
Ultimate Contributor
Well, I got some problems with http client on a file upload operation.
At first, I had to add
socket.Block()

in httpcli.cpp, line 131 in order to avoid a "resource temporary unavailable" error.
Now I can upload small and medium (let's say, some tenth of KBytes) files without problem, but if I try to send a file of around 800 KBytes, the server says "file partially transmitted".
I do have a MAX_UPLOAD of about 40 MBytes on server, and the original web app (that I'm trying to mimick) does it well.

Any hint ?

Max
Re: HTTP Client and file upload [message #18830 is a reply to message #18829] Sat, 25 October 2008 17:52 Go to previous messageGo to next message
mdelfede is currently offline  mdelfede
Messages: 1307
Registered: September 2007
Ultimate Contributor
ops, sorry, my mistake.... just a missing \r\n at the end of send protocol, which brings problems on txt/ps files Sad

The "Block()" problem is still there, but that's not a big one, just a small patch on httpcli.cpp Smile

Ciao

Max
Re: HTTP Client and file upload [message #25584 is a reply to message #18830] Tue, 02 March 2010 13:28 Go to previous messageGo to next message
forlano is currently offline  forlano
Messages: 1182
Registered: March 2006
Location: Italy
Senior Contributor
Hello,

I am resuming a Max very old post that looks related to my problem. I want to upload a file to a server where there is the postfile.php that looks like this
<html><head></head><body>
<?php
if (!isset($_POST['file'])) {
?>
    <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
    Enter file path <input type="text" name="file">
    </form>

<?php
}
else {
    echo 'File name: '.$_POST['file']  .'<br />';
}
?>
</body></html>


I would like to use the HttpClient class to simulate the file upload. I tried the following code after a search on the forum
#include <Web/Web.h>
using namespace Upp;
CONSOLE_APP_MAIN
{   	
	HttpClient x;
	x.Method(HttpClient::METHOD_POST);
	x.URL("http://localhost/test/postfile.php");
	//x.AddHeaders("Content-Type: application/x-www-form-urlencoded");
	x.KeepAlive(true);
	x.Post("file", LoadFile("myfile.txt"));
	String respond = x.ExecuteRedirect();
	SaveFile("headers.txt",x.GetHeaders());
	SaveFile("respond.html",respond);
}


It simply hangs without result but should be not very far from the right solution.
Thank you for any suggestion,

Luigi

EDIT: it seems to work after the comment of the line with
x.AddHeaders()

[Updated on: Tue, 02 March 2010 21:42]

Report message to a moderator

Re: HTTP Client and file upload [message #25680 is a reply to message #25584] Sun, 07 March 2010 19:23 Go to previous messageGo to next message
forlano is currently offline  forlano
Messages: 1182
Registered: March 2006
Location: Italy
Senior Contributor
I was too optimistic... it does not work Evil or Very Mad ,

Is it possible to have a simple example of file upload by using the HttpClient? I need to simulate the file upload by a web form like this
<html>
    <head></head>
    <body>
        <form enctype="multipart/form-data" action="uploader.php" method="POST">
		<input type="hidden" name="MAX_FILE_SIZE" value="100000" />
		Choose file: <input name="uploadedfile" type="file" /><br />
		<input type="submit" value="Upload File" />
		</form>
    </body>
</html> 

If it is not possible I'll use the Ftp client.
Thank you very much in advance,
Luigi

[Updated on: Sun, 07 March 2010 20:41]

Report message to a moderator

Re: HTTP Client and file upload [message #28068 is a reply to message #18829] Sat, 14 August 2010 14:28 Go to previous message
jeremy_c is currently offline  jeremy_c
Messages: 175
Registered: August 2007
Location: Ohio, USA
Experienced Member
You can view my very simple solution to the same problem:

http://www.ultimatepp.org/forum/index.php?t=msg&th=5394& amp;start=0&

I did not abstract it into something usable but if you just have one or two files to upload, it may work. If anyone is interested, I'll work on making maybe a postdata class that will build the multipart form data.

Jeremy
Previous Topic: HttpsClient problems?
Next Topic: HttpQuery - not working?
Goto Forum:
  


Current Time: Fri Mar 29 01:59:55 CET 2024

Total time taken to generate the page: 0.00929 seconds