I'm trying to upload a file through the HTTP POST.
I use the following components:
WebFilePicker1
WebFileUpload1
WebHttpRequest1
WebButton1
I don't like the appearance of the WebFileUpload1, so I put its property Visible to false.
In the OnChange event of the WebFilePicker1 I put the following code:
WebFilePicker1.Files[0].GetFileAsText;
and in its OnGetFileAsText event I put the code:
var
myFile: TFile;
begin
myFile:= WebFileUpload1.Files.Add;
myFile.Name := webfilepicker1.Files[0].Name;
myFile.Size := webfilepicker1.Files[0].Size;
...
I set the following properties of WebHttpRequest1:
Command=httpPOST
Headers=Content-Type=multipart/form-data
URL=http://myserver/upload
Finally in the OnClick event of WebButton1 I put the code:
WebHttpRequest1.PostData := 'uplodFile=' + WebFileUpload1.Files[0].Name;
WebHttpRequest1.Execute;
The server replies with an error, because the uploadFile is undefined. Nevertheless the following HTML code works well with the same server:
<html>
<body>
<form ref='uploadForm'
id='uploadForm'
action='http://myserver/upload'
method='post'
encType="multipart/form-data">
<input type="file" name="uploadFile" />
<input type='submit' value='Upload!' />
</form>
</body>
</html>
What am I doing wrong?