Solved

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

Posted on 2004-09-06
9
176 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 22

Expert Comment

by:Ferruccio Accalai
ID: 11989042
0
 
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Correct Component for Shopping Cart. 2 121
Dev Express grid collapse 2 47
Controlled Assessment GCSE - desperate help needed 4 112
enhance the following code 3 42
A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

726 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