Recent

Author Topic: Webserver to handle file UPLOAD (example)  (Read 9836 times)

new2linux

  • Jr. Member
  • **
  • Posts: 60
Webserver to handle file UPLOAD (example)
« on: July 01, 2014, 10:47:23 pm »
I've seen webserver examples, but all stop after implementing a simple GET handler. Not enough. I need to handle a POST at some port 12345 and store the data in a file.

There is also much confusion:
- Synapse has some documentation, can do an upload (but not receive one, how?). Seems somewhat abandoned.
- TFPHTTPServer, apparently native but totally undocumented?
- Indy: lost between versions?

So... I have no idea how to do it.

I have a preference for Synapse as I already use it to access Amazon S3.

I don't even have to preserve the filename, the content of the file is enough. Filesizes can be up to a few MB.

Alternatively, any other method to send a file over a (local) network, to some IP, would be fine also. EDIT: for example usings sockets directly??

I'm lost at this. Any pointers appreciated.

EDIT: needs to be cross-platform (initially Linux)
« Last Edit: July 01, 2014, 11:22:18 pm by new2linux »

parcel

  • Full Member
  • ***
  • Posts: 144
Re: Webserver to handle file UPLOAD (example)
« Reply #1 on: July 02, 2014, 04:00:07 am »
I made this for http file upload/download.
And It actually be a library.

It based on LNet httpserver component.
I test in windows 32bit and linux mint 17 64bit  :D

http://forum.lazarus.freepascal.org/index.php/topic,24686.0.html

new2linux

  • Jr. Member
  • **
  • Posts: 60
Re: Webserver to handle file UPLOAD (example)
« Reply #2 on: July 02, 2014, 02:55:08 pm »
I'd seen this. But rejected it based on the .exe inside a .zip.

Commandment number 13: one shall NOT execute an .exe from some random forum ;)

So sorry, I won't access it, nevermind the candy that is inside :/

Leledumbo

  • Hero Member
  • *****
  • Posts: 8833
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: Webserver to handle file UPLOAD (example)
« Reply #3 on: July 02, 2014, 06:34:30 pm »
TFPHTTPServer, apparently native but totally undocumented?
Check $(fpcsrcdir)/packages/fcl-web/examples/fptemplate/fileupload

kapibara

  • Hero Member
  • *****
  • Posts: 654
Re: Webserver to handle file UPLOAD (example)
« Reply #4 on: July 03, 2014, 06:59:39 am »
I think you did like me and downloaded the wrong zip that contains the program itself. :)

Get the zip with source, below the one with the executable.

I'd seen this. But rejected it based on the .exe inside a .zip.

Commandment number 13: one shall NOT execute an .exe from some random forum ;)

So sorry, I won't access it, nevermind the candy that is inside :/
Lazarus trunk / fpc 3.2.2 / Kubuntu 24.04 - 64 bit

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 12569
  • FPC developer.
Re: Webserver to handle file UPLOAD (example)
« Reply #5 on: July 03, 2014, 09:25:42 am »
The Indy9->Indy10 change was 7 years ago.  The reason why so many still use indy9 is that it is was delivered with older Delphi versions and they never upgraded.

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: Webserver to handle file UPLOAD (example)
« Reply #6 on: July 03, 2014, 10:42:05 am »
- Synapse has some documentation, can do an upload (but not receive one, how?). Seems somewhat abandoned.
Well, no, I suspect it's quite mature. There's still occasional fixes etc going in; see the Synapse trunk version.

True, a lot of the examples available via the synapse page are a bit old...
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

new2linux

  • Jr. Member
  • **
  • Posts: 60
Re: Webserver to handle file UPLOAD (example)
« Reply #7 on: July 03, 2014, 03:23:16 pm »
@marcov: There is a lack of news ever since 2006? This for example looks very messy:

http://wiki.lazarus.freepascal.org/Indy_with_Lazarus

I work on linux and I found info it wasn't ready yet. Could not find the link though.

@kapibara: isso mesmo  :-[, valeu cara. This is the zip download:

http://forum.lazarus.freepascal.org/index.php?action=dlattach;topic=24686.0;attach=9075

-

I am new to the socket stuff. I've seen lots of contradictory info, much confusion on the subject, including Delphi "abandoning sockets".

Seems like it could be (very) easy, but I didn't locate a good tut on the subject/concepts.



marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 12569
  • FPC developer.
Re: Webserver to handle file UPLOAD (example)
« Reply #8 on: July 03, 2014, 05:25:29 pm »
@marcov: There is a lack of news ever since 2006? This for example looks very messy:

http://wiki.lazarus.freepascal.org/Indy_with_Lazarus

That's because back then it was a special branch. That branch merged into mainstream Indy10, which should support FPC just fine now.
 

new2linux

  • Jr. Member
  • **
  • Posts: 60
Re: Webserver to handle file UPLOAD (example)
« Reply #9 on: July 03, 2014, 09:45:13 pm »
@marcov: There is a lack of news ever since 2006? This for example looks very messy:

http://wiki.lazarus.freepascal.org/Indy_with_Lazarus

That's because back then it was a special branch. That branch merged into mainstream Indy10, which should support FPC just fine now.

Spring cleaning would do wonders for Indy. 



new2linux

  • Jr. Member
  • **
  • Posts: 60
Re: Webserver to handle file UPLOAD (example)
« Reply #10 on: July 03, 2014, 09:54:46 pm »
I'm working directly with Sockets now, based on the Synapse echo demo. Indeed seems very simple, and it is instructive as it reveals the inner workings of the HTTP protocol.

That demo uses a  TTCPBlockSocket to listen to a port, then spawns a second TTCPBlockSocket to handle a connection. I am not interested in handling multiple connections, so, would this second TTCPBlockSocket perhaps be redundant? In other words, I could have handled the connection directly in/with the TTCPBlockSocket?





parcel

  • Full Member
  • ***
  • Posts: 144
Re: Webserver to handle file UPLOAD (example)
« Reply #11 on: July 05, 2014, 07:49:40 am »
I'd seen this. But rejected it based on the .exe inside a .zip.

Commandment number 13: one shall NOT execute an .exe from some random forum ;)

So sorry, I won't access it, nevermind the candy that is inside :/

You downloaded sample binary.

It's easy to use.

Code: [Select]
procedure TForm1.SetupMyHTTP;
var
  c: TBigFileURIHandler;
  //a:TCGIHandler;
  sdir: string;
begin
  if MyHttpServer<>nil then begin
    MyHttpServer.Disconnect(True);
    Sleep(100);
    FreeAndNil(MyHttpServer);
    loglist.AddLog('Disconnected.');
  end;

  MyHttpServer:=TBigFileLHTTPServerComponent.Create(self);
  MyHttpServer.Name:='Server1';
  MyHttpServer.OnError:=@LHTTPServerComponent1Error;
  MyHttpServer.OnAccept:=@LHTTPServerComponent1Accept;

  c:=TBigFileURIHandler.Create;
  c.Methods:=[hmHead, hmGet, hmPost];

  sdir:=Utf8ToAnsi(DirectoryEdit1.Directory);
  if sdir<>'' then
    if sdir[Length(sdir)]<>PathDelim then
      sdir:=sdir+PathDelim;
  c.DocRoot:=sdir;

  // c.UploadLimit:=40*1024*1024;
  c.UploadLimit:=1024*1024*1024;

  c.AuthEnable:=CheckBoxAuth.Checked;
  if c.AuthEnable then begin
    c.AuthUser:=Utf8ToAnsi(EditUser.Text);
    c.AuthPass:=Utf8ToAnsi(EditPass.Text);
  end;

  MyHttpServer.RegisterHandler(c);

  if not DirectoryExists(c.DocRoot) then
    CreateDir(c.DocRoot);
  {
  a:=TCGIHandler.Create;
  a.FCGIRoot:=ExtractFilePath(ParamStr(0))+'cgi-bin'+PathDelim;
  a.FDocumentRoot:=ExtractFilePath(ParamStr(0))+'files'+PathDelim;
  a.FEnvPath:=ExtractFilePath(ParamStr(0))+'cgi-bin'+PathDelim;
  a.FScriptPathPrefix:='cgi-bin/';
  LHTTPServerComponent1.RegisterHandler(a);
  }

  MyHttpServer.Port:=StrToIntDef(Edit1.Text,80);
  MyHttpServer.Listen(MyHttpServer.Port);

  loglist.AddLog(Format('Port %d',[MyHttpServer.Port]));

  if c.AuthEnable then
    loglist.AddLog(Format('Basic Authorization Mode! User: %s, Pass:%s',[c.AuthUser,c.AuthPass]));

  SaveDocPath;
end;

support multiupload like this.

Code: [Select]
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head>
<body>
<p><hr /></p>
<div>
<form name="file" method="post" action="/%ED%95%98%ED%95%98/%EB%AC%B4%EC%96%B4%EB%AC%B4%EC%96%B4/upload.action.htm" enctype="multipart/form-data">
<input type="file" name="fileupload">
<input type="file" name="fileupload">
<input type="file" name="fileupload">
<input type="submit" value="send">
<input name="MAX_FILE_SIZE" value="1073741824" type="hidden" /></form>
</div><p><hr /></p>
</body></html>
« Last Edit: July 05, 2014, 08:01:04 am by parcel »

 

TinyPortal © 2005-2018