Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

how to auto upload file through web in iis

Posted on 2001-07-14
10
Medium Priority
?
786 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 13

Accepted Solution

by:
Epsylon earned 1200 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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

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…
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…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

972 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