Search found 4 matches

by GoSane
Sat 05 Feb 2022 16:18
Forum: SecureBridge
Topic: Upload a file using PUT and ContentType = 'multipart/form-data'
Replies: 10
Views: 8491

Re: Upload a file using PUT and ContentType = 'multipart/form-data'

And here is a fully working code, adding the boundary stuff. Maybe there's a cleaner way to do it.
If filename contains non-ASCII (accented) characters, you have to encode it in quoted-printable format.

Code: Select all

procedure SendFile(idrealm,idannuaire:Integer; Filename:String);
Const APIendpoint = '/file/upload';
      Bearer      = 'eyJhbGciOiJIUzIiFMdxCX0PdvHIETXBKKYFtYDu_sPSiY1ZNLeUJg681s';
      APIurl      = 'https://rooturl.yourdomain.tld';
      APIport     = 8088;
      boundary    = '----------BOUNDARY'; // Feel free to add some randomness here
var
  Request: TScHttpWebRequest;
  Response: TScHttpWebResponse;
  ResponseStr: string;
  Stream: TFileStream;
  FinalStream: TMemoryStream;
  url: String;
  s:AnsiString;
begin
  url:=Format('%s:%d%s',[APIurl,APIport,APIendpoint])+Format('?realm_id=%d&idannuaire=%d',[idrealm,idannuaire]);
  Request := TScHttpWebRequest.Create(URL);
  Stream := TFileStream.Create(FileName, fmOpenRead);
  FinalStream:=TMemoryStream.Create;
  try
    Request.Method := rmPut;
    Request.ContentType := 'multipart/form-data; boundary='+boundary;
    Request.TransferEncoding := 'binary';
    Request.headers.Add('Authorization','Bearer '+Bearer);
    Request.KeepAlive:=True;

    s := '--'+boundary+^M+^J
        +'Content-Disposition: form-data; name="file"; filename="'+FileName+'"'+^M+^J
        +'Content-Type: */*'+^M+^J
        +^M+^J;
    FinalStream.Write(s[1],Length(s));
    FinalStream.CopyFrom(Stream,Stream.Size);
    s := ^M+^J+
         '--'+boundary+'--'+^M+^J;
    FinalStream.Write(s[1],Length(s));
    FinalStream.Position:=0;

    Request.ContentLength := FinalStream.Size;
    Request.SendChunked := True;
    Request.RequestStream := FinalStream;

    Response := Request.GetResponse;
    ResponseStr := Response.ReadAsString;
    ShowMessage(ResponseStr);
    Response.Free;
  finally
    FinalStream.Free;
    Stream.Free;
    Request.Free;
  end;
end;
by GoSane
Mon 19 Oct 2020 15:49
Forum: PostgreSQL Data Access Components
Topic: Speeding up Master/detail browsing
Replies: 3
Views: 19613

Speeding up Master/detail browsing

Hello,

I have a simple master/detail TPgQuery setup. Master has ~100000 records and detail has ~340000 (distributed quite evenly). I browse master by code with something like :

Code: Select all

while not qmaster.eof do begin
  qmaster.next;
end;
The problem is that it is extremely slow : ~15 seconds to navigate through 100 master records. I have set up a test program that does nothing (apart from measuring the time). That's about 500 records (100 master + 400 detail) in 15 seconds, that's 33 records/second :-(

qDetail's Mastersource is connected to the qMaster's Datasource, Masterfields and detailfields are filled with the (serial/integer) primary key of qMaster, qDetail's IndexFieldNames contains that same primary key. It is configured in FetchAll=True (slower to start but no network lag during traversal), Options.LocalMasterDetail is True.

The even stranger thing is that if I remove the IndexFieldNames, time to process 100 master records "falls" to 11 seconds. Wasn't this option supposed to speed up Master/detail?

I don't see what I could do to speed things up.

Thanks for your help.

Using Delphi 10.3 and PgDAC 6.2.4
by GoSane
Mon 18 Aug 2014 09:57
Forum: VirtualDAC
Topic: TVirtualTable.LoadFromDataset ?
Replies: 5
Views: 27137

Re: TVirtualTable.LoadFromDataset ?

Oops, sorry I missed it in the docs. Thanks !
by GoSane
Fri 15 Aug 2014 11:11
Forum: VirtualDAC
Topic: TVirtualTable.LoadFromDataset ?
Replies: 5
Views: 27137

TVirtualTable.LoadFromDataset ?

Is it possible to fill a virtualtable with the content of a TPgQuery ?

Thanks,