Jump to content

Mocte Sandoval

Members
  • Content Count

    12
  • Joined

  • Last visited

Posts posted by Mocte Sandoval


  1. Hi @omnibrain

     

    I have used Sergio's esegece components in the past I can only say good things about them, the main usage for us was messaging between the core of our software and mobile devices, the software is still running as of today but we are moving our projects from delphi to other technologies.

     

    Just to add to the conversation when we did that MQTT project  we tried with mosquitto and for us it was never reliable, I can't recall the exact details, but we ended using https://vernemq.com/ it is not available for windows but our server is Linux so no problem,  also you can use the open source version without incurring licensing costs as long as you make the build yourself instead of using the prebuilt binaries availables for download, and It's been rock solid to this day .

     

    Good luck with your project

     

    Regards

    Mocte


  2. 11 minutes ago, Remy Lebeau said:

    Why not continue using TIdMultipartFormDataStream for that?  It has an overloaded AddFormField() method that lets you specify a TStream for the input data.  You could store your bytes in a TMemoryStream or TBytesStream, or use Indy's own TIdMemoryBufferStream, etc.

    Yes, whatever value you specify in the "boundary" header, you need to add a leading "--" to in the body, and a trailing "--" at the end.

     

    Good to know, I'll give it a try tomorrow, thank you Remy


  3. Ok, I got rid of all initial "-"  so boundary is now e.g. boundary=4024b236a3a1 on header,  --4024b236a3a1 in body, and closing --4024b236a3a1--

     

    And all is working great now ! 

     

    Thank you so much Attila this was driving me nuts. 

     

    Edit: How can I mark this topic as resolved?


  4. Thank you Attila, I stripped that in my search of the correct way, added again with no luck.

     

    I'm attaching a sample of what the log looks like, I deleted a great part of its contents because the documents are confidential data but maybe some expert eyes can notice something I'm missing.

     

    BTW I think I missed the last line on the log  {"error":"multipart: NextPart: EOF"}  definitely there is something missing there.

    test.txt


  5. 1 hour ago, Attila Kovacs said:

    What happens if you set the stream's position to zero before posting?

    Just tested with the same result (400),  I didn't show it here but I have a TIdLogFile for logging the message, the data seems to be all in place, I suspect I am constructing the message in some way different from how TIdMultipartFormDataStream is processed by TidHttp and therefore it is possible I'm not sticking to the http spec for a multipart/form-data post but I'm failing to see where.
     


  6. Hi to all

     

    I don't ask here often but now I need some help with Indy ( which I don't use often either btw ).

     

    The scenario: 

     

    I need to upload "documents" ( mostly PDF, Tiff, Jpg ) usually from a file to a third party HTTP server, I am doing that perfectly fine with code like this ( just a snippet ) :

    var
      Params: TIdMultipartFormDataStream;
    Begin
      ...
        Params.AddFile(fileName, fullFilePath, 'application/octet-stream');
        http.Post('http://x.x.x.x:8996/service', Params, responseStream);
      ...
    End

    The endpoint from the server side receives the file and answers with code 201 which is expected.

     

    Now the problem, there are a lot of these "documents" stored on files on disk, each of these files contain a bunch of "documents" on a propietary format, which I'm succesfully extracting as an array of bytes, I can save them as individual files with TFileStream and view them with external tools, but I need to send these individual files to the http server, so for speeding up the process I want to avoid saving them to disk, so what i would like is to send the array of bytes straight to the server, here is an snippet from the code I am using so far:

    procedure SendFromBytes( const buffer: array of byte );
    var
      ...
      data, 
      idBoundary: String;
      ...
    Begin
      ...
         idBoundary := '---someboundaryId';
    
          StreamResp := TStringStream.Create('',TEncoding.UTF8);
          streamSrc  := TMemoryStream.create;
    
          http.Request.ContentType := sContentTypeFormData + idBoundary;
    
          data := idBoundary + CRLF +
            'Content-Disposition: form-data; name="'+name+'"' + CRLF + CRLF;
          streamSrc.Write(data[1], Length(data));
          streamSrc.WriteBuffer(Buffer[0], length(Buffer));
    
          data := CRLF +  idBoundary;
          streamSrc.Write(data[1], Length(data));
          http.Post('http://x.x.x.x:8996/service', StreamSrc, streamResp);
    ...
    End;

    But here I'm getting 400 Bad request, so I'm not sending the message as is expected by the server 

     

    Is there an Indy guru here who can help me find the cause? 

     

    Edit: I'm on Delphi XE3

    Edit 2: spelling on subject


  7. On 5/20/2019 at 12:27 PM, David Schwartz said:

    See if my CodeRage 9 presentation gives you any useful ideas:

     

    http://w5a.com/u/coderage-9-talk

     

    Hi David,  I just stumbled across this thread and saw your video, I remember seeing it sometime ago, at the end there is this link: http://goo.gl/8GRLDk but isn't available anymore, would you mind to share again the code of this sample or any other similar you have available?  I would like to play around with it if you don't mind.

     

    Thank you.

×