elGringo Posted August 30, 2016 Posted August 30, 2016 Hello, all !!! I'm writing mixed App VCL client + UniGUI Server. So, is that possible to use UniGUI as FTP Server? To plug from VCL and upload and get links to VCL app ? Thanks in advance!!! Quote
zilav Posted August 30, 2016 Posted August 30, 2016 SeverModule has event for custom HTTP requests, so you can POST a file as octet stream from VCL app to your UNI app. However I recommend to use cloud services like Amazon S3 for example. There are existing Delphi libs to manage cloud services and you'll get a working link when file is uploaded without cluttering your server. Quote
elGringo Posted August 30, 2016 Author Posted August 30, 2016 Zilav - thank you very much for the answer!!! I will try to do that for myself - but could your give a small example - an idea how to do that - if i will choose the 1 variant. One thing in that I write program that will be deployed on different VPS Windows Servers, so it must not depend on Amazon only. Also, I have Azure account - maybe there's complete lib for that task too... - but it also means dependence on Azure only... So I'm in process... Quote
zilav Posted August 30, 2016 Posted August 30, 2016 I made a simple demo app to post "test.txt" file and receive POST request in UniGUI. It will output encoded multipart data stream, google how to decode it with Indy, there are plenty of examples like this. Don't have time myself to implement that. I'd rather use clouds anyway. UniPostFile.zip 2 Quote
elGringo Posted August 31, 2016 Author Posted August 31, 2016 Zilav - thank you very much !!! I will post here my results anyway. And about clouds - i will test it too. Have a nice day there. Quote
zilav Posted August 31, 2016 Posted August 31, 2016 Zilav - thank you very much !!! I will post here my results anyway. And about clouds - i will test it too. Have a nice day there. Here is an example from my project where I generate thubmnails and upload them to S3 with public access for internet shop. function TFrameItems.UploadThumbnail(aStream: TStream; aName: string): Boolean; var s3: TAmazonS3; begin Result := False; s3 := TAmazonS3.Create(Self); try try s3.AccessKeyID := data.GetSetting('AWSAccessKeyId'); s3.SecretAccessKeyID := data.GetSetting('AWSSecretKey'); s3.AmzHeaders.Values['x-amz-acl'] := 'public-read'; s3.AmzHeaders.Values['x-amz-storage-class'] := 'REDUCED_REDUNDANCY'; s3.UploadObject(data.GetSetting('AWSBucketName'), aName, 'image/jpeg', aStream); Result := True; except // handle error here end; finally s3.Free; end; end; AmazonS3.zip Quote
elGringo Posted August 31, 2016 Author Posted August 31, 2016 TAmazonS3? Genious! I will test both variants on UniGUI Server and on my Azure cloud and will post my results here in a few days. Quote
elGringo Posted August 31, 2016 Author Posted August 31, 2016 And can this task decided with TidFTPServer and TidFTP? Quote
zilav Posted August 31, 2016 Posted August 31, 2016 And can this task decided with TidFTPServer and TidFTP? Only if you run a single instance of UniGui app on the host machine (standalone or server). ISAPI won't work at all. If you still insist on using FTP, then install any free FTP server. From your VCL app generate unique name for a file to upload (probably some hash), send it to FTP server with TIdFTP, then http POST uploaded unique file name to UniGUI app as I've shown you. Quote
elGringo Posted August 31, 2016 Author Posted August 31, 2016 My task quite simple - to put file (for example 123.jpg or 123.mp3 or 123.mp4) near UniServer from my vcl app and to get link - for example http://localhost:8077/123.jpg and to use it in vcl. It is clear for me that with ftp i will put it I need link in vcl app, so in that case http.post no needed? Also you say interesting thing - i'm trying to understand Only if you run a single instance of UniGui app on the host machine (standalone or server). ISAPI won't work at all. In attachment - picture from http://www.unigui.com/explore/technology-overview ISAPI Handler create MainModule which is creating DataModules and so on. So if to put IdFTPServer on MainModule for example - will it be multiplied to number of sessions? I ask because just want something embedded (some ftp server embedded or http server embedded) in my program to not to install hundered of additional programs. Quote
zilav Posted September 1, 2016 Posted September 1, 2016 In that case just redirect FTP server's default dir to any subfolder inside UniGUI's folder and upload there. No need to do anything in UniGUI app itself. Quote
elGringo Posted September 2, 2016 Author Posted September 2, 2016 Yes, i also came to that decision. Sheme is following to upload file from vcl app (Ftp Client) to ServerMachine -Check FTPServer Is Started, in not than start FTPServer as EXE on ServerMachine -send file from FTPClient -receive approval that file is uploaded ..next steps than next question - how remotely start EXE file on Server Machine from for example FTPClient? Quote
elGringo Posted September 2, 2016 Author Posted September 2, 2016 Maybe UniGUI Server can check and start FTP Server? They will be on the same machine Quote
elGringo Posted September 2, 2016 Author Posted September 2, 2016 Don't you know if I do like so procedure TMainForm.UniButton1Click(Sender: TObject); begin ShellExecute(Handle, 'open', 'c:\Windows\notepad.exe', nil, nil, SW_SHOWNORMAL); end; Do I start it on local client machine or on Server Machine? I will test it on my Azure today Quote
elGringo Posted September 2, 2016 Author Posted September 2, 2016 Ok. I tested ErrorCode:=shellAPI.ShellExecute(Handle, 'open', PWideChar('c:\Windows\System32\notepad.exe'), nil, nil, SW_SHOWNORMAL); this opens notepad on ServerSide - on my Azure Machine So, using this approach - I can start FTP Server on my Azure and any other EXE But how to start or stop remotely UniGUI.EXE Itself? Quote
WildFrag Posted September 5, 2016 Posted September 5, 2016 build isapi dll and no problem with autostart unigui application Quote
elGringo Posted September 5, 2016 Author Posted September 5, 2016 Yes. It is clear, but looked for alternative variants Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.