AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Programmierung allgemein Netzwerke Daten abholen von einem CakePHP Server
Thema durchsuchen
Ansicht
Themen-Optionen

Daten abholen von einem CakePHP Server

Ein Thema von MartinK · begonnen am 4. Okt 2014 · letzter Beitrag vom 8. Jan 2015
 
MartinK

Registriert seit: 21. Jun 2009
Ort: Germering (Germany)
89 Beiträge
 
Delphi 10.2 Tokyo Enterprise
 
#6

AW: Daten abholen von einem CakePHP Server

  Alt 8. Jan 2015, 10:47
Zwecks Vollständigekit halber hier ein weiteres CodeFragment, da ich denke das es evtl. weiteren Personen hilft die mal etwas ähnliches machen wollen

Ziel: Ein FileUpload auf den Server mittels eines sog "Multipart Form DataStreams". So etwas wird zB zum Uploaden von Bildern eingesetzt

lG Martin

Delphi-Quellcode:
Function TForm1.ACloud_UploadPicture(_PictureID, _OriPictureFPathAndName:String) : String;
Var
  POSTData: TIdMultipartFormDataStream;
  JSON: ISuperObject;
begin
  Result := '';
  try
    //generate a so called Multipart Object with
    //- the picture File itself. it is loaded as Stream form the path specified
    //- identifiers needed for the Cake server routines 'picture' , 'image/jpg'
    POSTData := TIdMultiPartFormDataStream.Create;
    POSTData .AddFile('picture', _OriPictureFPathAndName, 'image/jpg');

    IDHTTP.HandleRedirects := True;
    IDHTTP.Request.BasicAuthentication := false;
    IDHTTP.Request.Authentication := TIdBasicAuthentication.Create;
    IDHTTP.Request.Authentication.Username := aCloudLogin.Username;
    IDHTTP.Request.Authentication.Password := aCloudLogin.Password;
    //although we handle the Multipart message, servers answers are again JSON for easier interpretation
    IdHTTP.Request.ContentType := 'application/json';

    aCloudURL := URLEncode(aCloudServer + 'pictures/uplpic.json?PictureID=' + _PictureID+'.jpg');
    JSONResponse := IDHTTP.Post(aCloudURL, POSTData);
  except
    on E : Exception do
      Result := Result + 'Exception uploading an image to aCloud: "' + E.ClassName + '" "' + E.Message +'"';
  end;
  POSTData.Free;
  //---------------------------
  if Result <> 'then exit;
  //---------------------------
  //Now let's check if everythimng worked correctly. ...we interprte the Response returend from the Server
  //This is specific to your servers specifications and just an example on how it could be done
  JSON := SO();
  JSON := SO(JSONResponse); // Interprete the response to the JSON Super-Object (SO)
  If (Uppercase(JSON.S['response']) <> Uppercase('OK') ) OR
     (Uppercase(JSON.S['entityID']) <> Uppercase(_PictureID+'.jpg')) OR
     (Uppercase(JSON.S['entityType']) <> Uppercase('picturedata') ) OR
     (Uppercase(JSON.S['type']) <> Uppercase('u') )
     then Result := Result + 'Error responded updating an aCloud-picture: ' + JSONResponse;
end;
Martin Kuhn
  Mit Zitat antworten Zitat
 


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 06:00 Uhr.
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz