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 » [SOLVED] File upload example
[SOLVED] File upload example [message #52428] Mon, 23 September 2019 19:42 Go to next message
forlano is currently offline  forlano
Messages: 1071
Registered: March 2006
Location: Italy
Experienced Contributor
Hello,

I need to upload a file within my U++ app to a server, say folder "uploaded".
Is there a ready to use example/reference? I was not able to find it.

Thanks,
Luigi

[Updated on: Sun, 29 September 2019 16:48]

Report message to a moderator

Re: File upload example [message #52434 is a reply to message #52428] Fri, 27 September 2019 14:30 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 12050
Registered: November 2005
Ultimate Member
forlano wrote on Mon, 23 September 2019 19:42
Hello,

I need to upload a file within my U++ app to a server, say folder "uploaded".
Is there a ready to use example/reference? I was not able to find it.

Thanks,
Luigi


Which server? FTP? WebDAV?

Mirek
Re: File upload example [message #52435 is a reply to message #52434] Fri, 27 September 2019 14:57 Go to previous messageGo to next message
forlano is currently offline  forlano
Messages: 1071
Registered: March 2006
Location: Italy
Experienced Contributor
mirek wrote on Fri, 27 September 2019 14:30
forlano wrote on Mon, 23 September 2019 19:42
Hello,

I need to upload a file within my U++ app to a server, say folder "uploaded".
Is there a ready to use example/reference? I was not able to find it.

Thanks,
Luigi


Which server? FTP? WebDAV?

Mirek


It is not FTP (no authentication).
However I am not sure about WebDAV.

Here is what I want to replicate (more o less)

https://www.w3schools.com/php/php_file_upload.asp

Just a standard file upload, but instead to do it via browser I want use my U++ app.
I think the client side should be done with few instructions.

Thanks,
Luigi
Re: File upload example [message #52436 is a reply to message #52435] Sat, 28 September 2019 10:19 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 12050
Registered: November 2005
Ultimate Member
I see. You need HttpRequest::Post. Something like (this is sending JSON):

	HttpRequest r(url);
	r.ContentType("application/json");
	r.PostData(LoadFile("C:/test/some.json")));
	r.Execute());


(there are MANY variations to this depending on target server, but HttpRequest can cover all that I have encountered so far).
Re: File upload example [message #52439 is a reply to message #52436] Sun, 29 September 2019 13:11 Go to previous message
forlano is currently offline  forlano
Messages: 1071
Registered: March 2006
Location: Italy
Experienced Contributor
Thanks.
After many tests I was able to perform the wanted operation.
Here is the U++ method

void fileupload::Upload()
{
    String url = "http://localhost/uploads/transfer.php";
    HttpRequest r(url);
    String fn = "C:/upp/out/MyApps/MSBT17.Gui/test.pdf";
    String s = LoadFile(fn); 
    r.POST();
    r.Part("file", s , "multipart/form-data", fn);
    r.Execute();   
}


and this is the PHP script connected with the previous code:
<?php
//transfer.php
$target = "./". basename( $_FILES["file"]["name"] ) ; 
if(move_uploaded_file($_FILES["file"]["tmp_name"], $target)) echo "1";
else echo "0";
?>


Is there a way to get the echoed "1" or "0" with r.something()?
Edit: Yes, of course:

String a;
a = r.Execute();

a contains the server answer.

Luigi

[Updated on: Sun, 29 September 2019 16:47]

Report message to a moderator

Previous Topic: Skylark- REST service returning JSON. Is it possible?
Goto Forum:
  


Current Time: Thu Oct 17 13:25:39 CEST 2019

Total time taken to generate the page: 0.01438 seconds