
  TAS_FormUpload version 1.0
  --------------------------

  Copyright (c) 2000 AriseSoft

  e-mail:     combocontrol@iname.com
  home page:  http://www.combocontrol.cjb.net/

  This unit is a "promotionware": you are free to use it
  as you wish in any projects, however we ask you to visit our website
  and read about our other nice products. Chances are, you'll get
  an extra bonus - right from our home page :-)

  It is example of HTML Form Upload ("multipart/form-data" MIME type - RFC 1867)
  for Delphi developers who create isapi-dll. Now you can
  uploading files from the web and store it in a custom database.
  (~60 KB limit of upload size).

  HTML-code:
---
<html><head><title>File upload</title></head><body>
  <form action="demo.dll/upload" method="post" enctype="multipart/form-data">
    <input type="file" name="file">
    <input type="submit" value="Upload">
  </form>
</body></html>
---

  Demo of Web Server:
---
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, HTTPApp, AS_FormUpload;

type
  TWeb = class(TWebModule)
    procedure WebItemUploadAction(Sender: TObject; Request: TWebRequest;
      Response: TWebResponse; var Handled: Boolean);
    procedure WebItemDownloadAction(Sender: TObject; Request: TWebRequest;
      Response: TWebResponse; var Handled: Boolean);
  private
    FStoredContentData: string;
    FStoredContentType: string;
  public
    { Public declarations }
  end;

var
  Web: TWeb;

implementation

{$R *.DFM}

procedure TWeb.WebItemUploadAction(Sender: TObject; Request: TWebRequest;
  Response: TWebResponse; var Handled: Boolean);
var
  FormUpload: TAS_FormUpload;
begin
  FormUpload := TAS_FormUpload.Create(Request.ContentType, Request.Content);
  try
    FStoredContentData := FormUpload.ContentData;
    FStoredContentType := FormUpload.ContentType;
    Response.Content := Format('File: %s has been uploaded.', [FormUpload.FileName]);
  finally
    FormUpload.Free;
  end;
end;

procedure TWeb.WebItemDownloadAction(Sender: TObject; Request: TWebRequest;
  Response: TWebResponse; var Handled: Boolean);
var
  ContentStream: TStringStream;
begin
  Response.ContentType := FStoredContentType;
  ContentStream := TStringStream.Create(FStoredContentData);
  ContentStream.Position := 0;
  Response.ContentStream := ContentStream;
  { ^ note: do not free the stream because the response object
    will handle that task }
end;

end.
---

