Solved

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

Posted on 2004-09-06
9
174 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
indy tidtcpclient threading issue 8 63
error 1.1 400 Bad request idhttp delphi 18 55
Delphi Form ownership 4 73
Not able to call Delphi XE10 dll function from Delphi 6.0 4 18
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.

920 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

14 Experts available now in Live!

Get 1:1 Help Now