mazluta
Members-
Content Count
38 -
Joined
-
Last visited
Everything posted by mazluta
-
upload file to the server for indexing in the server using browser UNIGUI application
mazluta posted a topic in Network, Cloud and Web
I have a document management system (DMS) written in Delphi UNIGUI. I have a scanning system with many capabilities written in Delphi DESKTOP. I want to scan with the DeskTop application and when finished send the scanned file to the server (Unigui) to perform the filing on the server. The server should receive the file, save it in the temporary area and pop up a filing screen. What is the best way to do it? -
upload file to the server for indexing in the server using browser UNIGUI application
mazluta replied to mazluta's topic in Network, Cloud and Web
this is the solution https://forums.unigui.com/index.php?/topic/36456-upload-file-to-the-server-for-indexing-in-the-server-using-browser-unigui-application/#comment-169303 -
upload file to the server for indexing in the server using browser UNIGUI application
mazluta replied to mazluta's topic in Network, Cloud and Web
yes. sorry. office - internet - cloud server. the desktop will be installed in any of the clients 10-50 per day. 5 users. since i new to web development i would like to hear what the masters idea -
upload file to the server for indexing in the server using browser UNIGUI application
mazluta replied to mazluta's topic in Network, Cloud and Web
Hi David. yes, you right. Since the Server (UNIGUI) is always running i thought to use it as "FTP". on the Desktop App var HTTP: TIdHTTP; FormData: TIdMultipartFormDataStream; url : string; FilePath : string; ResultInt : Int64; begin Try HTTP := TIdHTTP.Create(nil); FormData := TIdMultipartFormDataStream.Create; try FilePath := 'c:\a\M1.pdf'; URL := PrmUrlAddress + ':' + IntToStr(PrmUrlPort) + '/Indexing'; ResultInt := GetUniqueNumber; JustWriteToLog('url=' + url); JustWriteToLog('ResultInt=' + IntToStr(ResultInt)); FormData.AddFile('file', FilePath, 'application/octet-stream'); // 'file' is the form field name expected by the server FormData.AddFormField('UniqueName', IntToStr(ResultInt)); HTTP.Post(URL, FormData); // URL is the endpoint, e.g., http://yourserver:port/upload ShowMessage('File uploaded successfully - Status Code = ' + IntToStr(HTTP.ResponseCode)); ShowMessage('Response Text = ' + HTTP.ResponseText); except on E: Exception do ShowMessage('Failed to upload file: ' + E.Message); end; Finally FormData.Free; HTTP.Free; End; and on the server (UNIGUI) Var FileStream: TFileStream; SavePath : string; FileFirstName : String; FormData: TIdMultiPartFormDataStream; begin if ARequestInfo.URI = '/Indexing' then begin FormData := TIdMultiPartFormDataStream.Create; FileFirstName := The Extra PARAM Field SavePath := 'C:\a\' + FileFirstName + '.pdf'; FileStream := TFileStream.Create(SavePath, fmCreate); try // Copy the incoming data to the file stream FileStream.CopyFrom(ARequestInfo.PostStream, ARequestInfo.PostStream.Size); finally FileStream.Free; end; AResponseInfo.ResponseText := 'File Saved OK'; Handled := True; end; end; then after getting 200 status from the server, send another one with the unique no and go to indexing process. -
Error sending data: (12029) A connection with the server could not be established.
mazluta posted a topic in Network, Cloud and Web
i have rest server witch listen to port 8090. it suppose to get JSON with some params. i have web APP that run in some domain - www.hanibaal-test.co.il the server is in localhost :8090 on the client side i do : procedure TSignedDocumentsFrm.DoSignDocument_CA(PdfFileName : String); var HttpClient : TNetHTTPClient; Response : IHTTPResponse; JsonData : TStringStream; AppUrl : String; ResultPdfFileName : String; SignServerAddress : String; PdfBase64 : String; JpgBase64 : String; EncrtpPassWord : String; begin PdfBase64 := dm_Image.ImgToBase64(PdfFileName); JpgBase64 := dm_Image.ImgToBase64(UniMainModule.UserDataRec.User_Logo_FileName); EncrtpPassWord := EncryptStringCK(UniMainModule.UserDataRec.User_TokenPassword, AppEncryPass); JustWriteToLog('EncrtpPassWord = ' + EncrtpPassWord); SignServerAddress := UniMainModule.UserDataRec.User_CA_Sign_HttpAddrs + ':' + IntToStr(UniMainModule.UserDataRec.User_CA_Sign_Port) + '/sign'; JustWriteToLog('SignServerAddress : ' + SignServerAddress); Try JsonData := TStringStream.Create('{"PdfBase64Type": "base64", ' + ' "PdfBase64": "' + PdfBase64 + '", ' + ' "JpgBase64Type": "base64",' + ' "JpgBase64": "' + JpgBase64 + '", ' + ' "LogoTop": ' + IntToStr(UniMainModule.UserDataRec.User_Logo_Top) + ',' + ' "LogoLeft": ' + IntToStr(UniMainModule.UserDataRec.User_Logo_Left) + ',' + ' "LogoWidth": ' + IntToStr(UniMainModule.UserDataRec.User_Logo_Width) + ',' + ' "LogoHeight": ' + IntToStr(UniMainModule.UserDataRec.User_Logo_Height) + ',' + ' "CheckTokenStr": "' + UniMainModule.UserDataRec.User_Token_SerialNO + '",' + ' "CardSerialNO": "' + UniMainModule.UserDataRec.User_Token_SerialNO + '",' + ' "EncrptPassword": "' + EncrtpPassWord + '",' + ' "ReasonToSign": "' + UniMainModule.UserDataRec.User_SignReason + '",' + ' "ImageOpacity": ' + IntToStr(UniMainModule.UserDataRec.User_ImageOpacity) + '}', TEncoding.UTF8); AppUrl := UniApplication.UniSession.URL; if AppUrl[Length(AppUrl)] = '/' then begin AppUrl[Length(AppUrl)] := ' '; AppUrl := Trim(AppUrl); end; HttpClient := TNetHTTPClient.Create(nil); //HttpClient.CustomHeaders['Origin'] := AppUrl;; HttpClient.CustomHeaders['Content-Type'] := 'application/x-www-form-urlencoded'; HttpClient.PreemptiveAuthentication := true; JustWriteToLog('After Set HttpClient Origin to : ' + AppUrl); // Set request content type to JSON HttpClient.ContentType := 'application/json'; //HttpClient.Accept := 'application/json'; // Send POST request with JSON data JustWriteToLog('Before Post Data to Server'); JustWriteToLog('JsonData = ' + JsonData.ToString); Response := HttpClient.Post(SignServerAddress, JsonData); // Check response if Response.StatusCode = 200 then begin ResultPdfFileName := RemoveBackSlashChar(UniServerModule.LocalCachePath) + '\MyResult.Pdf'; Base64ToPDF(Response.ContentAsString,ResultPdfFileName); //JustWriteToLog(Response.ContentAsString); //ShowMessage('Response: ' + Response.ContentAsString); end else begin ShowMessage('Error: ' + Response.StatusText); end; finally JsonData.Free; HttpClient.Free; end; end; on the server side i have : procedure TMyWebModule.WebModuleBeforeDispatch(Sender: TObject; Request: TWebRequest; Response: TWebResponse; var Handled: Boolean); begin JustWriteToLog('start dispath'); JustWriteToLog('Request.Method = ' + Request.Method); Response.CustomHeaders.Values['Access-Control-Allow-Origin'] := '*'; Response.CustomHeaders.Values['Access-Control-Allow-Headers'] := 'Origin, X-Requested-With, Content-Type, Accept'; Response.CustomHeaders.Values['Access-Control-Allow-Methods'] := 'GET, POST, PUT, DELETE, OPTIONS'; Response.CustomHeaders.Values['Access-Control-Allow-Credentials'] := 'true'; Response.CustomHeaders.Values['Access-Control-Allow-Private-Network'] := '*'; Response.CustomHeaders.Values['Access-Control-Expose-Headers'] := ''; Response.CustomHeaders.Values['Access-Control-Max-Age'] := '86400'; JustWriteToLog('On WebModuleBeforeDispatch - After Set Response.SetCustomHeader Access-Control-Allow-Origin' ); if Trim(Request.GetFieldByName('Access-Control-Request-Headers')) <> '' then begin JustWriteToLog('On WebModuleBeforeDispatch - Trim(Request.GetFieldByName(Access-Control-Request-Headers))'); Response.CustomHeaders.Values['Access-Control-Allow-Headers'] := Request.GetFieldByName('Access-Control-Request-Headers'); Handled := True; end; if SameText(Request.Method, 'OPTIONS') then begin JustWriteToLog('On WebModuleBeforeDispatch - if SameText(Request.Method, Option)'); Response.StatusCode := 204; // No Content Handled := True; end; end; something is blocking the request. and i don't no what.... i close firewall + AV i don't see where and who block my call i don't get any message in the logs (not in the client and not in the server), except "...connection can not be...." i don't see any error in the console.log. When I run both app in my localhost - all work fine and i get CA digital Sign PDF File -
Error sending data: (12029) A connection with the server could not be established.
mazluta replied to mazluta's topic in Network, Cloud and Web
Thanks @Olli73 i will try it -
Error sending data: (12029) A connection with the server could not be established.
mazluta replied to mazluta's topic in Network, Cloud and Web
Hi. thanks for your answer. i close the Firewall. i close the AV. i add inbound roll to open port TCP 8090 for CORS it should "Ask" the server in the local for permition and i respond "OK" for CORS, but it did not rich to this "question". i even don't know what is blocking? where is it blocking? who is blocking> -
Hi, i'm using TIdMessageBuilderHtml to build the message body from HTML, the base HTML is Attach - myMail.html. it's Base64 + some CSS - style="height:144px; width:120px; when open this HTML with browser all look fine. after sending this with the SMPT protocol the size of the image become the TRUE SIZE of the image. and this is not what i want. myMail.msg is the email as received in my outlook. how can i fix it? uSendSMTPMail.pas myMail.html MyMail.msg
-
The image in the target mail don't respect the height/width prop
mazluta replied to mazluta's topic in Indy
you right. sorry. PngGraphic := TPngGraphic.Create; try DibGraphic := TDibGraphic.Create; try Result := Base64ToImg(Base64Str, DibGraphic, FileExtn); if not Result then Exit; PngGraphic.Assign(DibGraphic); finally DibGraphic.Free; end; if PngGraphic.Empty then Exit; did you read the TAO? it's old as the wheel of time...... -
The image in the target mail don't respect the height/width prop
mazluta replied to mazluta's topic in Indy
Thanks Remy. no doubt your code is more efficient. but on save the base64 as PNG is not the right way. the base 64 is string depend on the file type. i work with Envision https://www.intervalsoftware.com/envision.html So i load any one of the type with appropriate object and convert it all to PNG, create the PNG, load it to the Html Files of the mail body and send the mail. You are the MASTER. UDDF - Tao of Programming.mht -
The image in the target mail don't respect the height/width prop
mazluta replied to mazluta's topic in Indy
yeeee that abug yes. you right 🙂 -
The image in the target mail don't respect the height/width prop
mazluta replied to mazluta's topic in Indy
Ok. That Work. function Tdm_Image.DoFixMailTextBody(MAIL_TextBody : String; Attach_Base64 : TStringList) : String; Var CurTry : Integer; CurPos : Integer; CurChar : Integer; UniqueNo : Integer; StartFrom : Integer; EndTo : Integer; Base64Str : String; base64 : TBase64Encoding; StrArray : TBytes; DibGraphic : TDibGraphic; TmpPNG : TPngGraphic; TestStr : String; fTempDir : String; PngFileName : String; NewImgSrc : String; FileExtn : String; begin Result := MAIL_TextBody; Attach_Base64.Clear; CurTry := 0; While CurTry < 250 Do begin CurTry := CurTry + 1; FileExtn := ''; FileExtn := 'png'; CurPos := pos(Base64_01,MAIL_TextBody); if CurPos < 1 then begin FileExtn := 'jpg'; CurPos := pos(Base64_02,MAIL_TextBody); end; if CurPos < 1 then begin FileExtn := 'svg'; CurPos := pos(Base64_03,MAIL_TextBody); end; if CurPos < 1 then begin FileExtn := 'png'; CurPos := pos(Base64_04,MAIL_TextBody); end; if CurPos < 1 then begin FileExtn := 'jpg'; CurPos := pos(Base64_05,MAIL_TextBody); end; if CurPos < 1 then begin FileExtn := 'bmp'; CurPos := pos(Base64_06,MAIL_TextBody); end; if CurPos < 1 then begin FileExtn := 'gif'; CurPos := pos(Base64_07,MAIL_TextBody); end; if CurPos < 1 then begin FileExtn := 'tif'; CurPos := pos(Base64_08,MAIL_TextBody); end; if CurPos < 1 then begin FileExtn := 'wmf'; CurPos := pos(Base64_09,MAIL_TextBody); end; if CurPos < 1 then begin FileExtn := 'emf'; CurPos := pos(Base64_10,MAIL_TextBody); end; if CurPos > 0 then begin UniqueNo := GetUniqueNumber; {This will be tje dic Number} StartFrom := 0; EndTo := 0; // first find the , char - after that start the base64 string For CurChar := CurPos + 5 to Length(MAIL_TextBody) Do begin if MAIL_TextBody[CurChar] = ',' then begin StartFrom := CurChar + 1; Break; end; end; // the find the next " char - this close the base64 string For CurChar := StartFrom + 5 to Length(MAIL_TextBody) Do begin if MAIL_TextBody[CurChar] = '"' then begin EndTo := CurChar - 1; Break; end; end; // take the Base64 String And Convert to png file DibGraphic := TDibGraphic.Create; Try fTempDir := RemoveBackSlashChar(RemoveSlashChar(UniServerModule.LocalCachePath)); Base64Str := Copy(MAIL_TextBody,StartFrom, EndTo - StartFrom); if Base64ToImg(Base64Str,DibGraphic, FileExtn) then begin PngFileName := fTempDir + '\' + IntToStr(UniqueNo) + '.png'; TmpPNG := TPngGraphic.Create; Try TmpPNG.Assign(DibGraphic); TmpPNG.SaveToFile(PngFileName); Attach_Base64.Add(PngFileName); Delete(MAIL_TextBody, CurPos + 5, EndTo - CurPos - 4); NewImgSrc := 'cid:' + IntToStr(UniqueNo) +'.png'; Insert(NewImgSrc, MAIL_TextBody, CurPos + 5); Finally FreeAndNil(TmpPNG); End; end; Finally FreeAndNil(DibGraphic); End; end else begin Break; end; end; Result := MAIL_TextBody; end; and to send the Mail : function SendMailBySMTP(SMTP_Host : String; SMTP_User : String; SMTP_Password : String; SMTP_Port : Integer; Send_FromAddress : String; Send_FromName : String; Send_ToAddress : String; Send_ToName : String; Send_Subject : String; Send_TextBody : String; UseCid : Boolean; Attach_Base64 : TStringList; Attach_List : TStringList) : Boolean; Var cid : WideString; SMTP : TIdSMTP; AMsg : TidMessage; CurAttch : Integer; FoundBase64 : Boolean; Const Base64_01 : String = 'src="data:image/png;base64,'; Base64_02 : String = 'src="data:image/jpeg;base64,'; Base64_03 : String = 'src="data:image/image/svg+xml;base64,'; Base64_04 : String = 'src="data:image/image/apng;base64,'; Base64_05 : String = 'src="data:image/jpg;base64,'; Base64_06 : String = 'src="data:image/image/bmp;base64,'; Base64_07 : String = 'src="data:image/image/gif;base64,'; Base64_08 : String = 'src="data:image/image/tiff;base64,'; Base64_09 : String = 'src="data:image/image/wmf;base64,'; Base64_10 : String = 'src="data:image/image/emf;base64,'; begin Result := False; Try if UseCid Then begin FoundBase64 := False; if (pos(Base64_01,Send_TextBody) > 0) Or (pos(Base64_02,Send_TextBody) > 0) Or (pos(Base64_03,Send_TextBody) > 0) Or (pos(Base64_04,Send_TextBody) > 0) Or (pos(Base64_05,Send_TextBody) > 0) Or (pos(Base64_06,Send_TextBody) > 0) Or (pos(Base64_07,Send_TextBody) > 0) Or (pos(Base64_08,Send_TextBody) > 0) Or (pos(Base64_09,Send_TextBody) > 0) Or (pos(Base64_10,Send_TextBody) > 0) then FoundBase64 := True; if not FoundBase64 Then UseCid := False; end; if UseCid then begin end; Try SMTP:= TIdSMTP.Create(nil); SMTP.Disconnect(); SMTP.Host := SMTP_Host; SMTP.Username := SMTP_User; SMTP.Password := SMTP_Password; SMTP.Port := SMTP_Port; AMsg := TidMessage.Create(nil); AMsg.Encoding := meDefault; AMsg.ContentType := 'text/html'; if Attach_List.Count > 0 then AMsg.ContentType := 'multipart/mixed'; AMsg.CharSet := 'UTF-8'; //AMsg.ContentTransferEncoding := '8bit'; AMsg.subject := UTF8Encode(Send_Subject); AMsg.From.Name := UTF8Encode(Send_FromName); AMsg.From.Address := Send_FromAddress; with AMsg.Recipients.Add do begin Name := UTF8Encode(Send_ToName); Address := Send_ToAddress; end; with TIdMessageBuilderHtml.Create do try HtmlCharSet := 'UTF-8'; Html.Text := UTF8Encode(Send_TextBody); if Attach_List.Count > 0 then begin for CurAttch := 0 To Attach_List.Count - 1 Do begin Attachments.Add(Attach_List.Strings[CurAttch]); end; end; if Attach_Base64.Count > 0 then begin for CurAttch := 0 To Attach_Base64.Count - 1 Do begin HtmlFiles.Add(Attach_Base64.Strings[CurAttch]); end; end; FillMessage(AMsg); finally Free; end; SMTP.Connect; SMTP.Send(AMsg); Result := True; Finally AMsg.Free; SMTP.Disconnect; SMTP.Free; End; Except on E: Exception do begin AddMsgToEventLog('', J_FirstFileName(ParamStr(0)), 'Fail send SMPT Mail, Error :' + e.Message,EVENTLOG_ERROR_TYPE, 4, 1); Result := False; end; End; end; function IsTherBase64InHTML(HTML_Text : String) : Boolean; Const Base64_01 : String = 'src="data:image/png;base64,'; Base64_02 : String = 'src="data:image/jpeg;base64,'; Base64_03 : String = 'src="data:image/image/svg+xml;base64,'; Base64_04 : String = 'src="data:image/image/apng;base64,'; Base64_05 : String = 'src="data:image/jpg;base64,'; Base64_06 : String = 'src="data:image/image/bmp;base64,'; Base64_07 : String = 'src="data:image/image/gif;base64,'; Base64_08 : String = 'src="data:image/image/tiff;base64,'; Base64_09 : String = 'src="data:image/image/wmf;base64,'; Base64_10 : String = 'src="data:image/image/emf;base64,'; begin Result := (pos(Base64_01,HTML_Text) > 0) Or (pos(Base64_02,HTML_Text) > 0) Or (pos(Base64_03,HTML_Text) > 0) Or (pos(Base64_04,HTML_Text) > 0) Or (pos(Base64_05,HTML_Text) > 0) Or (pos(Base64_06,HTML_Text) > 0) Or (pos(Base64_07,HTML_Text) > 0) Or (pos(Base64_08,HTML_Text) > 0) Or (pos(Base64_09,HTML_Text) > 0) Or (pos(Base64_10,HTML_Text) > 0); end; thanks Remy for your Help. -
The image in the target mail don't respect the height/width prop
mazluta replied to mazluta's topic in Indy
Thanks. i will try it -
The image in the target mail don't respect the height/width prop
mazluta replied to mazluta's topic in Indy
i see i can build the eMail for Gmail using IDMessage. i can iterate in all base64 img convert them to png file but i dont see way to embedded the image it self into the html message back... -
The image in the target mail don't respect the height/width prop
mazluta replied to mazluta's topic in Indy
ok. now there is new problem. Gmail want show message with image base on base64 string. is there simple convert outlook message to Gmail Message? -
The image in the target mail don't respect the height/width prop
mazluta replied to mazluta's topic in Indy
that work. 1. i remove the html conflict. 2. i gat the return string from the CkEditor. 3. i build simple HTML with 2 function. one to iterate all image. and for each <img> element i convert the base64 to be the same as the attribute (second function). 4. now, when i send the - "message" - its all look "normal".. thank Remy and Alexander. BTW - attach is the HTML file i build to convert the Images mtTag_11197140.html -
The image in the target mail don't respect the height/width prop
mazluta replied to mazluta's topic in Indy
Thanks Alexander. i'm checking it all now. -
The image in the target mail don't respect the height/width prop
mazluta replied to mazluta's topic in Indy
Hi Remy Thanks for you detailed answers. i see your point. i will check it all and get back to you -
The image in the target mail don't respect the height/width prop
mazluta replied to mazluta's topic in Indy
Hi Remy Thanks for your answers. 1. What versions of Delphi and Indy are you using? delphi 10.3 + indy 10 2. Did you compare the HTML that Outlook has to the HTML that you sent? yes they are the same. 3. the msg file was just to let those how answer to see what i get. 4. why are you UTF-8 encoding. because of the Hebrew characters. 5. Your HTML has conflicting charsets in its <meta> elements. what are the conflicts? 6. the 'body' is result of CkEditor. and i don't want to change there components. and the <IMG> is most likely the Company logo. maybe if i change the base64 to the size of the style - it will work. -
The image in the target mail don't respect the height/width prop
mazluta replied to mazluta's topic in Indy
i tried but with no help. it's look like outlook does what he want.... myTest-2.msg -
I write RESTserver with Delphi 10.3 The Service accepts 3 parameters. One of them is the string hold base64 string of PDF file. When I create the Base64 String with Delphi as : function ConvertPdfFileToBase64D(PdfFileName : String; var Base64Str : String) : Boolean; var success : Boolean; b64 : String; fBytes : TBytes; fSize : Integer; function FileToBytes(const AFileName: string; var Bytes: TBytes): Boolean; var Stream: TFileStream; begin if not FileExists(AFileName) then begin Result := False; Exit; end; Stream := TFileStream.Create(AFileName, fmOpenRead); try fSize := Stream.Size; SetLength(Bytes, fSize); Stream.ReadBuffer(Pointer(Bytes)^, fSize); finally Stream.Free; end; Result := True; end; begin Result := False; Base64Str := ''; if FileToBytes(PdfFileName,fBytes) then begin //Base64Str := TNetEncoding.Base64.EncodeBytesToString(fBytes, fSize); Base64Str := TNetEncoding.Base64.EncodeBytesToString(fBytes); Result := True; End; end; when i get this base64 in the Delphi REST Api I decode the string and successfully save a PDF file. when i send base64 string created in Visual Studio C# like : Byte[] fileBytes = File.ReadAllBytes(@textBox1.Text); var content = Convert.ToBase64String(fileBytes); I get different base64 strings. what is the right way to send base64 string as PDF file from C# to Delphi REST API
-
PDF File Send as Base64 from c# to Delphi REST
mazluta replied to mazluta's topic in Network, Cloud and Web
Thanks Remy, I Will try the binary data and the JSON way. -
PDF File Send as Base64 from c# to Delphi REST
mazluta replied to mazluta's topic in Network, Cloud and Web
Hi Remy. First: thanks for the knowledge. Secondly: the "DevApp" field was sent as C# from the start. Third: the line - content = Uri.EscapeDataString(content); fix it all put "%2B" as replaced for any "+" sign and the Delphi Rest got the '+' sign as it should be without doing anything in the service. Fourth: when i sent the Base64 string back with '+' sign in the response the C# read it well and saved the PDF to wherever it should be saved. -
PDF File Send as Base64 from c# to Delphi REST
mazluta replied to mazluta's topic in Network, Cloud and Web
Hi Hi Remy Lebeau if the Solution is to do that in C# : https://stackoverflow.com/questions/7842547/request-parameter-losing-plus-sign descriptionsUrlAddition = descriptionsUrlAddition.replace("+", "%2B"); Then my Solution is the same i tried : request.ContentType = "application/form-data"; request.ContentType = "application/raw"; some give there solution like content = Uri.EscapeDataString(content); and that work fine. -
PDF File Send as Base64 from c# to Delphi REST
mazluta replied to mazluta's topic in Network, Cloud and Web
Hi Remy Lebeau i think your answer is the right answer. this is the C# Code private void button1_Click(object sender, EventArgs e) { string requestUrl = "http://185.185.135.XXX:YYYY/MyTest"; HttpWebRequest request = HttpWebRequest.CreateHttp(requestUrl); request.Method = "POST"; // Optionally, set properties of the HttpWebRequest, such as: request.AutomaticDecompression = DecompressionMethods.Deflate | DecompressionMethods.GZip; request.ContentType = "application/x-www-form-urlencoded"; // Could also set other HTTP headers such as Request.UserAgent, Request.Referer, // Request.Accept, or other headers via the Request.Headers collection. //Byte[] fileBytes = File.ReadAllBytes(@textBox1.Text, System.Text.Encoding.ASCII); Byte[] fileBytes = File.ReadAllBytes(@textBox1.Text); var content = Convert.ToBase64String(fileBytes,Base64FormattingOptions.None); // Set the POST request body data. In this example, the POST data is in // application/x-www-form-urlencoded format. string postData = "DevApp=C#&Base64Type=base64&username=mazluta&base64=" + content; using (var writer = new StreamWriter(request.GetRequestStream())) { writer.Write(postData); } // Submit the request, and get the response body from the remote server. string responseFromRemoteServer; using (HttpWebResponse response = (HttpWebResponse)request.GetResponse()) { using (StreamReader reader = new StreamReader(response.GetResponseStream())) { responseFromRemoteServer = reader.ReadToEnd(); fileBytes = Convert.FromBase64String(responseFromRemoteServer); File.WriteAllBytes(@"c:\a\mytest.pdf", fileBytes); MessageBox.Show("File c:\\a\\mytest.pdf signed and saved"); } } } This is The Delphi Rest Code : procedure TMyWebModule.MyWebModuleactSignAction(Sender: TObject; Request: TWebRequest; Response: TWebResponse; var Handled: Boolean); Var RequestObject: TJSONObject; PdfBase64 : string; RspBase64 : string; UserName : string; Base64Type : string; DevApp : string; CachPdfPath : String; CachFilesPath : String; TmpPdfFile : String; TmpTxtFile : String; DstPdfFileName : String; SignParam : TSignParam; PfxFileName : String; PfxPassword : String; UserDataRec : TUserDataRec; ParamArea : TParamArea; UserSignData : TUserSignData; //aPdfBase64 : AnsiString; aRspBase64 : PAnsiChar; aTmpPdfFile : AnsiString; aTmpTxtFile : AnsiString; SaveTextList : TStringList; MyBytesArr : TBytes; CurChar : Integer; begin ( JustWriteToLog(' '); JustWriteToLog('======'); JustWriteToLog('reqeust=base64 at : ' + formatdatetime('dd/mm/yyyy hh:nn:ss:zzz', now)); JustWriteToLog(' '); UserName := Request.ContentFields.Values['UserName']; Base64Type := Request.ContentFields.Values['Base64Type']; PdfBase64 := Request.ContentFields.Values['Base64']; DevApp := Request.ContentFields.Values['DevApp']; JustWriteToLog(' '); JustWriteToLog('UserName='+UserName); JustWriteToLog(' '); JustWriteToLog('Base64Type='+Base64Type); JustWriteToLog(' '); JustWriteToLog('DevApp='+DevApp); JustWriteToLog(' '); JustWriteToLog('Base64='+PdfBase64); JustWriteToLog(' '); UserDataRec := dm_DB.GetUserData(UserName); ParamArea := dm_DB.LoadAppParams; JustWriteToLog('User request = ' + UserName); JustWriteToLog('Start PDF 50 char = ' + Copy(PdfBase64, 1, 50)); if UserDataRec.Found then JustWriteToLog('User Found') else JustWriteToLog('User not found'); if ParamArea.Found then JustWriteToLog('ParamArea Record found'); If not ParamArea.Found Then begin Response.Content := 'Fail load Server params'; Response.StatusCode := 400; exit; end; UserSignData := dm_DB.GetUserSignRec(UserDataRec, ParamArea); If not UserSignData.Found Then begin Response.Content := 'Fail load UserSignData params'; Response.StatusCode := 400; exit; end; JustWriteToLog('Find User SignData, PfxFile = ' + UserSignData.User_PfxFileName); JustWriteToLog('Find User SignData, LogoFile = ' + UserSignData.User_LogoFileName); CachPdfPath := GetBaseAppPath + '\' + DSHTTPWebDispatcher1.CacheContext; if CachPdfPath[length(CachPdfPath)] = '/' Then CachPdfPath[length(CachPdfPath)] := ' '; CachPdfPath := Trim(CachPdfPath); ForceDirectories(CachPdfPath); Try TmpPdfFile := CachPdfPath + '\Tmp_' + GetRandomStr + '.pdf'; TmpTxtFile := ChangeFileExt(TmpPdfFile,'.txt'); if UpperCase(DevApp) = UpperCase('C#') then begin JustWriteToLog('Before Replace PdfBase64 : ' + PdfBase64); SetLength(MyBytesArr,Length(PdfBase64)); MyBytesArr := TEncoding.ASCII.GetBytes(PdfBase64); for CurChar := 1 to Length(PdfBase64) do begin if Ord(MyBytesArr[CurChar]) = 32 then MyBytesArr[CurChar] := byte(43); end; PdfBase64 := TEncoding.ASCII.GetString(MyBytesArr); JustWriteToLog('After Replace PdfBase64 : ' + PdfBase64); ConvertBase64ToPdfFile(PdfBase64,TmpPdfFile); end else if UpperCase(Base64Type) = UpperCase('Base64') then begin ConvertBase64ToPdfFile(PdfBase64,TmpPdfFile); end else begin ConvertBase64MimeToPdfFile(PdfBase64,TmpPdfFile); end; JustWriteToLog('PDF File : ' + TmpPdfFile + ' Saved'); Except on e: exception do begin JustWriteToLog('Error on Save PDF File : ' + e.Message); Response.StatusCode := 390; Exit; end; End; DstPdfFileName := CachPdfPath + '\Rslt_' + GetRandomStr + '.pdf'; CachFilesPath := GetBaseAppPath + '\Files'; so - it looks that when I read the value of the Base64 field - the + becomes space PdfBase64 := Request.ContentFields.Values['Base64'];