?
Solved

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

Posted on 2004-09-06
9
Medium Priority
?
182 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 23

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 23

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
Industry Leaders: 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 23

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 23

Accepted Solution

by:
Ferruccio Accalai earned 375 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 23

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

Independent Software Vendors: 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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Screencast - Getting to Know the Pipeline
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Suggested Courses
Course of the Month14 days, 1 hour left to enroll

807 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