Forum > General

How to copy file to web

<< < (4/4)

egsuh:

--- Quote ---You probably just need to add laz_synapse to Required Packages in Project Inspector, like Tron said.
--- End quote ---

This is right.

I use httpsend instead of ftpsend. The file name could be httpsend.pp, not httpsend.pas, etc. Not sure. But once the laz_synapse is included in the required packages, you won't try to find the position of the file.

With httpsend, I attach an example of uploading file. 


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---uses HttpSend;...function Taq_r_5.UploadImage(tpid, filename: string;out Msg: string): boolean;var   AStrm: TMemoryStream;   AStrl : TStringList;   tfn: string;begin   Result:= false;    if FileExists(filename) then begin      tfn := tpid + ExtractFileExt(filename);  // this is to process the filename at server end.       AStrm := TMemoryStream.Create;      AStrl := TStringList.Create;    // This is to receve returned Webserver content       try          AStrm.LoadFromFile(filename);          Result := HttpPostFile(URL + 'UploadImage', tpid, tfn, AStrm, AStrl);                             // (URL, FieldName, FileName, Data, ResultData)          Msg := trim(astrl.text);  // astrl.text is returned text from server          Result:= Msg = tfn;   // My webserver returns the filename if everything is done correctly.       finally        AStrl.Free;        AStrm.Free;      end;   end   else Result := False;end; 
The function to call is

      HttpPostFile(URL, FieldName, FileName, FileStream, ReturnStrings)

Here, parameters are :

- URL  : the URL that receives the file
- FieldName:  As this is "post" method, there is a fieldname. In HTML example of  <input type=file name="myfile">, it is the value of "name".
- FileName :  This is your local file name. It does not mean that this filename will be used by server to save the file, depending on the server side. Anyway it's server's role.
- File stream: the stream of file that you want to upload.
- RetrunStrings :  the returned texts from webserver will be stored here, as TStrings.

Hope this is helpful.  Msg, tfn, etc. are for my own purposes.

Navigation

[0] Message Index

[*] Previous page

Go to full version