Solved

how to auto upload file through web in iis

Posted on 2001-07-14
10
764 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
ID: 6282196
It's read-only for security reasons...
0
 

Author Comment

by:gutian
ID: 6282368
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
ID: 6282431
Try the http component of the Indy's:

http://www.nevrona.com/Indy/Download.html
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
LVL 13

Accepted Solution

by:
Epsylon earned 300 total points
ID: 6282494
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
ID: 6283535
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
 
LVL 13

Expert Comment

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

Author Comment

by:gutian
ID: 6283970
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
ID: 6284951
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
ID: 6286053
thanks for your kind help,I have resoled the problem.
0
 
LVL 13

Expert Comment

by:Epsylon
ID: 6286767
Alright then. Thanks for the points.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
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…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

820 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