Page 1 of 1

Upload files to a web site

Posted: Sun Oct 02, 2011 9:23 pm
by Support
This script will upload a file to a web site, showing how to set the multipart/form-data

Code: Select all

Output.Clear;

FName = SelectFile('File to upload','');
if FName = Nothing then Terminate;

F = New(File);
F.Open(FName);
F.Seek(BeginningOfFile);

DecodeFileName(FName, [fn, ex], [FileName,Extension]);

Link = New(URL);

Link.Location = Input('Enter the URL to upload the file to:');
if Link.Location = Nothing then Terminate;
Link.Referer = Link.Location;

Link.AddHeader('Content-Type: multipart/form-data; boundary=---------------------------7da23915ad0a2c');

pd = '-----------------------------7da23915ad0a2c'+crlf+
     'Content-Disposition: form-data; name="file1"; filename="'+fn+ex+'"'+crlf+
		 'Content-Type: application/x-zip-compressed'+crlf+crlf+
		 F.Content+
		 crlf+crlf+'-----------------------------7da23915ad0a2c--'+crlf;

Link.Post(pd);

Output(Link.ServerText);