title: How can I retrieve an attachment in a Cloudant database with Delphi?
body: <p>I have successfully created a Bluemix Cloudant document and did Put an attachment to that doc with a Delphi program. I'm also able to retrieve that attachment via a BAT-file, but I should like to do it with Delphi 2009. I get 
  a HTTP/1.1 200 OK response, I don't know where to get the attachment
  The code:</p>
  
  <pre><code>  program httpsGet;
  
    {$R *.res}
    {$APPTYPE CONSOLE}
  
    uses
      IdHTTP, IdSSLOpenSSL, IdGlobal, SysUtils,IniFiles, Classes;
  
    var
      HTTP: TIdHTTP;
      RequestBody: TStream;
      ResponseBody: string;
      LHandler: TIdSSLIOHandlerSocketOpenSSL;
      json: string;
      F:  textfile;
      s:  string;
      id,rev: string;
      Dir,user,password,mapp,butik: string;
      IniFile:  TInifile;
      a,i,x,Antdocs:  integer;
    begin
    //  Read ini-file and get user / password
      Dir:=ExtractFilePath(ParamStr(0));
      IniFile:=TIniFile.create(Dir + 'Credentials.ini');
      user:=IniFile.Readstring('Credentials','User','');
      password:=IniFile.Readstring('Credentials','Password','');
      IniFile.Destroy;
  
      id:='02d42fc7c5966b2ab7d27a3c9942a77e';
      rev:='2-904b6ca2f8883e35b931d138acc969c6';
      json:='{ "selector": {"_id":"' + id + '"}, "fields": "_attachment" } ';
  
      HTTP := TIdHTTP.Create;
      try
        try
          RequestBody := TStringStream.Create(json, TEncoding.UTF8);
          LHandler := TIdSSLIOHandlerSocketOpenSSL.Create(nil);
  
          try
            WriteLn(' RequestBody: ' + json);
            WriteLn('');
            HTTP.Request.BasicAuthentication:= true;
            HTTP.ConnectTimeout:= 10000;
            HTTP.Request.UserName := user;
            HTTP.Request.Password := password;
            HTTP.Request.Accept := 'application/json';
            HTTP.Request.ContentType := 'application/json';
            HTTP.IOHandler:=LHandler;
            ResponseBody := HTTP.Get('https://' + user + '.cloudant.com/pmu/');
            WriteLn(' ResponseBody: ' + ResponseBody);
            WriteLn(HTTP.ResponseText);
          finally
            RequestBody.Free;
            Lhandler.Free;
          end;
        except
          on E: EIdHTTPProtocolException do
          begin
            WriteLn(E.Message);
            WriteLn(E.ErrorMessage);
          end;
          on E: Exception do
          begin
            WriteLn(E.Message);
          end;
        end;
      finally
        HTTP.Free;
      end;
  
      ReadLn;
      ReportMemoryLeaksOnShutdown := True;
    end.
  </code></pre>
  
  <p>Output is:</p>
  
  <blockquote>
    <p>RequestBody: { "selector": {"_id":"02d42fc7c5966b2ab7d27a3c9942a77e"},
    "fields": "_attachment" } ResponseBody:
    {"update_seq":"331-g1AAAAPHeJzLYWBgEMhgTmFQSUlKzi9KdUhJMjTQS8rVTU7WLc3WNTDUS87JL01JzCvRy0styQGqZkpkSOL___9_ViIHSJ8yQh9-bUkCQDJJHqxTAFWnGQGdCiCd-mCdoqg6jQjoNADptAfr5CTNl0kOIK3-YK3iqJZaEtAZANIZD9YpSZpHE0A688E6hUjzaAFIZz1YJz9pHs1jAZIMDUAKqLsfI4QJeBaiewJE9_ysRHlU3ebE6F4A0b0-K1GaJE9DdG-A6N6flahIjscPQLSfJzWWIbovQHTfJzWmIbofQHS_z0rkJcPjHyC6QekzCwCYMTXF","db_name":"pmu","sizes":{"file":9239940,"external":2290914,"active":2392413},"purge_seq":0,"other":{"data_size":2290914},"doc_del_count":130,"doc_count":2,"disk_size":9239940,"disk_format_version":6,"data_size":2392413,"compact_running":false,"instance_start_time":"0"}
    HTTP/1.1 200 OK</p>
  </blockquote>
  
  <p>I have expected the attachment to be the ResponseBody.
  The Cloudant doc looks as follows:
  <a href="https://i.stack.imgur.com/Kk4ym.png" rel="nofollow noreferrer">Doc layout for specified id</a></p>
  
  <p>Can anybody give me a hint?
  Regards</p>