4

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

Kevin Jacobs
  • 69
  • 1
  • 3
  • 1
    you should provide a code that "isn't working" before someone would try to help you... –  Jul 31 '11 at 06:34
  • Code...>>> http://pastebin.com/sRFj3u7z <<<...Code – Kevin Jacobs Jul 31 '11 at 07:41
  • 2
    you are not sending the "actual" image in your code, please read http://forums2.atozed.com/viewtopic.php?f=7&t=14992 gambit's comment, it should help you achieve what you need, if you have trouble, then please post the code and point the issue. Also, knowing your version of Delphi(i.e. 7, 2009, 2010, XE, etc.) and Indy should help us even more. –  Jul 31 '11 at 08:11

1 Answers1

1

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;
Kevin
  • 11
  • 1