Error in stream

Good Morning,

We're trying to load a CSV file into a stream and it's giving an error.

Arq2 : TMemoryStream;
PathArq : string;
PathArq := 'C:\sincron\temp\produtos.txt' ;
Arq2 := TMemoryStream.Create;
Arq2.LoadFromStream(spreadsheet); // the error is on this line

procedure TMemoryStream.LoadFromStream(Stream: TStream);
Count: Int64;
Stream.Position := 0; // Here that generates the excess
Count := Stream.Size;
if Count <> 0 then Stream.ReadBuffer(FMemory^, Count);

error: Http request stream cannot change position

The file is an 855k CSV.


It seems spresdsheet is not an instantiated object (TStream)


What is spreadsheet? What is its type? How is it being instantiated?

function TLeitorExcelController.ImportarProdutoCsv(Planilha: TStream): boolean;

Dados.csv sent via POST

It still not clear where Planilha is coming from.
In any case, if it's a stream from Sparkle, it might be unidirecional only. You can't use LoadFromStream. You should copy one stream from another using buffers.
Something like this:

procedure CopyStream(Source, Dest: TStream);
  TempBufferSize = 16384;
  Buffer: TBytes;
  BufLen: Int64;
  BytesRead: Cardinal;
  BufLen := TempBufferSize;
  SetLength(Buffer, BufLen);
    BytesRead := Source.Read(Buffer[0], BufLen);
    if BytesRead > 0 then
      Dest.Write(Buffer[0], BytesRead);
  until (BytesRead <> BufLen);

Or you can simply get the content as bytes, not stream. But I can't say more as I don't know where Planilha is coming from.

It's always worked that way.
The data file.csv sent via POST on a request that will consume that importProductCSV endpoint

(Sempre usamos assim, e do nada começou esse problema. O arquivo criado dados.csv é enviado via POST numa requisição que consome nossa API, eu passei a imagem do nosso código ai) Acredito que nessa ultima versão de vocês, houve alguma mudança nesse sentido, so não sabemos como passar a usar esse recurso agora). Vou tentar usar esse copyStream que vc passou.

Do you have a suggestion?