Reputation: 69
I have the API key and read the sparse documentation on their site, but still having trouble getting this to work so if anyone has any examples they could share then that would be great. I do not need to worry about videos or anything fancy, just a simple upload with the return information will suit my needs.
uses IdHttp;
function PostData:string;
var
url: string;
text: string;
http: TIDHttp;
valid: boolean;
param: TStringList;
begin
http := TIDHttp.Create(nil);
http.HandleRedirects := true;
http.ReadTimeout := 5000;
param := TStringList.create;
param.Clear;
param.Add('fileupload=c:\image.png');
param.Add('key=MY_API_KEY');
param.Add('tags=tag1,tag2');
valid := true;
url := 'http://www.imageshack.us/upload_api.php';
try
text := http.Post(url, param);
except
valid := false;
end;
if valid then
PostData := text
else
PostData := '';
end;
Thx. Kevin
Upvotes: 4
Views: 2444
Reputation: 11
I pretty much did the exact same thing last nite. Thx tho.
procedure TForm1.Button1Click(Sender: TObject);
var
MPData: TIdMultiPartFormDataStream;
sResponse: string;
begin
MPData := TIdMultiPartFormDataStream.Create;
MPData.AddFile('fileupload','c:\image.png','image/png');
MPData.AddFormField('tags','testfile,flyasia');
MPData.AddFormField('public','no');
MPData.AddFormField('key','API_KEY_HERE');
sResponse := IdHTTP1.Post('http://www.imageshack.us/upload_api.php', MPData);
MPData.Free;
Memo1.Text := sResponse;
end;
Upvotes: 1