Solved

how to auto upload file through web in iis

Posted on 2001-07-14
10
755 Views
Last Modified: 2010-04-06
<form action=/script/uploadfile.asp ENCTYPE="multipart/form-data"
           METHOD=POST>
<input type=file name="filename">
</form>
I want to set file value by programing instead of manual selection.
but the inputfileelement.value is readonly
0
Comment
Question by:gutian
  • 6
  • 4
10 Comments
 
LVL 13

Expert Comment

by:Epsylon
Comment Utility
It's read-only for security reasons...
0
 

Author Comment

by:gutian
Comment Utility
I know it is read-only for reason ,I just want to know do it by any ways.
If I post the file with Sendrequestex,how can I do .
Thanks
0
 
LVL 13

Expert Comment

by:Epsylon
Comment Utility
Try the http component of the Indy's:

http://www.nevrona.com/Indy/Download.html
0
 
LVL 13

Accepted Solution

by:
Epsylon earned 300 total points
Comment Utility
Then tru this:


procedure TForm1.Button1Click(Sender: TObject);
var
  Request       : TMemoryStream;
  FileData      : TMemoryStream;
  Response      : TStringStream;
  tempArray     : array[0..10000] of char;
  tempString    : String;
  strFileSize   : String;
  InFile        : String;
const
  NewLine = chr(13) + chr(10);
begin
  Screen.Cursor := crHourGlass;

  InFile := 'c:\test.zip';

  // Set the properties for HTTP
  HTTP.ProtocolVersion                := pv1_1;
  HTTP.Request.Username               := '';
  HTTP.Request.Password               := '';
  HTTP.Request.ProxyServer            := '';
  HTTP.Request.ProxyPort              := 80;
  http.Request.ContentEncoding        := 'multipart/form-data';

  try

    // create streams
    Response  := TStringStream.Create('');
    Request   := TMemoryStream.Create;
    FileData  := TMemoryStream.Create;

    // load file data
    FileData.LoadFromFile( InFile );
    FileData.Seek( 0, soFromBeginning );
    // copy form data
    TempString := '';
    TempString := TempString + '-----------------------------7d18914904ee' + NewLine;
    TempString := TempString + 'Content-Disposition: form-data; name="UserName"' + NewLine;
    TempString := TempString + '' + NewLine;
    TempString := TempString + edUserName.text + NewLine;
    TempString := TempString + '-----------------------------7d18914904ee' + NewLine;
    TempString := TempString + 'Content-Disposition: form-data; name="PassWord"' + NewLine;
    TempString := TempString + '' + NewLine;
    TempString := TempString + edPassWord.text + NewLine;
    TempString := TempString + '-----------------------------7d18914904ee' + NewLine;
    TempString := TempString + 'Content-Disposition: form-data; name="FileSize"' + NewLine;
    TempString := TempString + '' + NewLine;
    TempString := TempString + '1234567' + NewLine;
    TempString := TempString + '-----------------------------7d18914904ee' + NewLine;
    TempString := TempString + 'Content-Disposition: form-data; name="DataFileName"; filename="' + InFile + '"' + NewLine;
    TempString := TempString + 'Content-Type: application/octet-stream' + NewLine;
    TempString := TempString + '' + NewLine;

    // Add data to post
    FillChar( temparray, SizeOf( temparray ), #0 );
    strpcopy( temparray, tempstring );
    Request.Write( temparray, length(tempstring) );
    Request.Seek( 0, soFromEnd );
    Request.CopyFrom( FileData, FileData.Size );

    // copy form data
    TempString := '';
    TempString := TempString + '' + NewLine;
    TempString := TempString + '-----------------------------7d18914904ee' + NewLine;
    TempString := TempString + 'Content-Disposition: form-data; name="Submit"' + NewLine;
    TempString := TempString + '' + NewLine;
    TempString := TempString + 'Submit' + NewLine;
    TempString := TempString + '-----------------------------7d18914904ee--'  + NewLine;
    // Add data to post
    FillChar( temparray, SizeOf( temparray ), #0 );
    strpcopy( temparray, tempstring );
    Request.Write( temparray, length(tempstring) );

    // post file
    try
      HTTP.Post( edUrl.Text, Request, Response);
    except
      showmessage( "Failed!")
    end;

    // write out debug text
    memo1.lines.Add('===[TForm1.Post - Response.DataString]=================');
    memo1.Lines.add( Response.DataString );

  finally
    Response.Free;
    Request.Free;
    FileData.Free;
    Screen.Cursor := crDefault;
  end;
end;
0
 

Author Comment

by:gutian
Comment Utility
thanks.BTW I want to build it in a dlls,how can I do.
I have build a dlls,but when I close main form,an error
show
0
Highfive Gives IT Their Time Back

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!

 
LVL 13

Expert Comment

by:Epsylon
Comment Utility
What error? Closing the main form of the DLL?
Showing some code could help...
0
 

Author Comment

by:gutian
Comment Utility
function PostData(hHandle:THandle;vUrl,vFileName,SavePath:string):Boolean;external 'uprequest.dll'

this is the call
if PostData(application.Handle,Url,Filename,Path) then
    showmessage('very good');

when I close the main form ,it tell me
project ..\dlls\dllcall,exe raised too many consecutive execptions:'access violation at 0x343343:read of address 0x00ea25f0'.process stopped use step or run to continue
0
 
LVL 13

Expert Comment

by:Epsylon
Comment Utility
Do you know about the limitation when using strings as parameter in dll functions?

  Important note about DLL memory management: ShareMem must be the
  first unit in your library's USES clause AND your project's (select
  Project-View Source) USES clause if your DLL exports any procedures or
  functions that pass strings as parameters or function results. This
  applies to all strings passed to and from your DLL--even those that
  are nested in records and classes. ShareMem is the interface unit to
  the BORLNDMM.DLL shared memory manager, which must be deployed along
  with your DLL. To avoid using BORLNDMM.DLL, pass string information
  using PChar or ShortString parameters.


I don't know if this is causing the exceptions. I need more info...
0
 

Author Comment

by:gutian
Comment Utility
thanks for your kind help,I have resoled the problem.
0
 
LVL 13

Expert Comment

by:Epsylon
Comment Utility
Alright then. Thanks for the points.
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

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…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

728 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