Solved

How can I upload a file from form to ASP file?

Posted on 2004-09-06
9
173 Views
Last Modified: 2012-05-05
Let's say I have opendialog component with it's value FileName.
Then I have ASP based web page, which should basically accept file upload.

I have found some examples of ASP page, but I have no Idea how to send info to ASP page.

Which components should I use?
0
Comment
Question by:Povilas
  • 5
  • 4
9 Comments
 
LVL 22

Expert Comment

by:Ferruccio Accalai
ID: 11988917
It depends on how works the ASP webpage...

For example if the only needs is to pass a parameter to the asp page you can simply use the Browser passing the parameters to it...

something like:
uses
shellapi

ShellExecute(0,'open',PChar('www.somesite.com\uploadpage.asp?File='+filename),nil,nil,0);
0
 
LVL 1

Author Comment

by:Povilas
ID: 11988967
I would like something without opening browser. I really need something that would let me upload file to a web server and basically only from Delphi form.
0
 
LVL 22

Expert Comment

by:Ferruccio Accalai
ID: 11989031
so you could use a ftp uploader component like indy tidFTP, but this means that you have to build a FTP location on your site.

Then from your application you can easly let the user to select the file and send it via ftp using your ftp connection settings directly from your application.

You can find the component and a FTPDemo on http://www.indyproject.org/
0
 
LVL 22

Expert Comment

by:Ferruccio Accalai
ID: 11989042
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 1

Author Comment

by:Povilas
ID: 11989178
I have found this tutorial:
http://www.matlus.com/scripts/website.dll/Tutorials?DelphiTCPIP&IndyMultiPartFormData&5

The problem is that server side code is not available and project file download doesn't work :-(
0
 
LVL 22

Accepted Solution

by:
Ferruccio Accalai earned 125 total points
ID: 11989245
Form me all is working fine....

BTW i've downloaded it and moved to my ftp... you can get it here now
www.afsoftware.it\Downloads\IndyMultipartFormData.zip
0
 
LVL 22

Expert Comment

by:Ferruccio Accalai
ID: 11989450
BTW using a TidFTP you can do this

procedure TForm1.Button1Click(Sender: TObject);
begin
If OpenDialog1.execute then
   begin
      with IdFtp1 do begin
         Host := 'ftp.somesite.com'; //your site ftp address
         UserName := 'User'; //the site username
         Password := 'Password'; //and the password
         try
            Connect;
            ChangeDir('/UploadDir'); //go to the dir on the site where you have to upload the file
            TransferType := ftBinary;
            IdFTP1.Put(OpenDialog1.FileName, ExtractFileName(OpenDialog1.FileName)); //and upload the file
         finally
            IdFTP1.Quit;
         end;
      end;
    end;
end;
0
 
LVL 1

Author Comment

by:Povilas
ID: 11995112
There are problems:

//Delphi procedure:
procedure TForm1.Button2Click(Sender: TObject);
Const CRLF = #13#10;
Var aStream: TMemoryStream;
      Params: TMemoryStream;
      S: String;
begin
 aStream := TMemoryStream.create;
 Params := TMemoryStream.Create;
 HTTP.Request.ContentType := 'multipart/form-data; boundary=-----------------------------7cf87224d2020a';
 try
  S := '-----------------------------7cf87224d2020a' + CRLF +
  'Content-Disposition: form-data; name="csv"; filename="d:abc.csv"' + CRLF +
  'Content-Type: text/plain' + CRLF + CRLF +
  'file one content. Contant-Type can be application/octet-stream or if '+
  'you want you can ask your OS fot the exact type.' + CRLF +
  '-----------------------------7cf87224d2020a' + CRLF +
  'Content-Disposition: form-data; name="game_number"' + CRLF + CRLF + 'hello2' + CRLF +
  '-----------------------------7cf87224d2020a--';
 Params.Write(S[1], Length(S));
 with HTTP do begin
  try
  HTTP.Post('http://www.test.com/test_upload.asp', Params, aStream);
 except
 on E: Exception do
 showmessage('Error encountered during POST: ' + E.Message);
 end;
 end;
aStream.WriteBuffer(#0' ', 1);
showmessage(PChar(aStream.Memory));
except
end;
end;

is there simplier example?
0
 
LVL 1

Author Comment

by:Povilas
ID: 11997194
I found this example that works:
http://4homepages.de/forum/viewtopic.php?t=4786
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now