Jump to content

Recommended Posts

Posted

Component: UnimFileUpload (TUnimFileUpload)
Parent: UnimFormAtendimentoVeiculoPrestadorM
LastAjaxEvent: upload
Class: Exception
Message: EOF Mark not found.

Is there any way to avoid this error?

Posted
procedure TUnimFormAtendimentoVeiculoPrestadorM.UnimFileUploadMultiCompleted(Sender: TObject; Files: TUniFileInfoArray);
begin
  if Length(Files) > 0 then
  begin
    try
      for var _File in Files do
      begin
        if (_File.Stream <> nil) and (_File.Stream.Size > 0) then
        begin
          var lFileName := _File.FileName;
          lFileName := TStringUtils.RemoveAcento(lFileName);

          Self.FClientImagem.Service<IServiceAnexo>.AnexarByTipoAwsS3(Self.FAtendimentoServico.AtendimentoVeiculo.Empresa.Id,
            UniMainModule.UserInfo.IdUsuario,
            lFileName,
            Self.FAtendimentoServico.AtendimentoVeiculo.ClassName, '',
            Self.FAtendimentoServico.AtendimentoVeiculo.Id,
            _File.Stream);

          var lAtendimento := Self.FControllerAtendimento.Find(Self.FAtendimentoServico.AtendimentoVeiculo.Id);

          if lAtendimento <> nil then
          begin
            Self.FControllerAtendimento.AddHistorico(lAtendimento,'ADD Imagem LINK: ' + lFileName,  _TIPO_HISTORICO_INTERNO);
            Self.FControllerAtendimento.Save(lAtendimento);
          end;
        end;
      end;
    except
      on E: EXDataOperationRequestException do
      begin
        TMessageUtils.Error(E.ErrorMessage);
        Exit;
      end;

      on E: Exception do
        TMessageUtils.Error(E.Message);
    end;
  end;
end;

This is my code, the error occurs, when taking an image from the gallery, I can't simulate it, I have no idea how this happens.

  • 2 weeks later...
Posted
Date: 26/05/2025 15:59:37
User: xxxxxxxxxxxxxxx - Mobile
Agent: Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) SamsungBrowser/28.0 Chrome/130.0.0.0 Mobile Safari/537.36
Versão: 3.0.0.893
IP: 
URL: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Navegador: chrome
Navegador Versão: 0
OS: android
SessionID: 3_oba7dh2Q5r11102D5D2
Component: btnAnexarImagem (TUnimFileUploadButton)
Parent: UniFormConsLancBeneficioFornecedorM
LastAjaxEvent: upload
Class: Exception
Message: EOF Mark not found.

 

Posted

Hello @picyka

I think the possible reasons include:

  • The connection was interrupted during the upload
  • The user minimized or closed the browser before completion
  • Unstable internet connection (common on mobile devices)
  • A corrupted or invalid file
Posted
On 5/28/2025 at 4:19 PM, picyka said:

The problem is that I can't even simulate it, I would like to at least be able to handle the error.

Date: 03/06/2025 10:31:41
User: xxxxxx.ro - Mobile
Agent: Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) SamsungBrowser/28.0 Chrome/130.0.0.0 Mobile Safari/537.36
Versão: 3.0.0.899
IP: 
URL: xxxxxx
Navegador: chrome
Navegador Versão: 0
OS: android
SessionID: 3_EEoYzzadyu1110EB4E4
Component: UnimFileUpload (TUnimFileUpload)
Parent: UnimFormAtendimentoVeiculoPrestadorM
LastAjaxEvent: upload
Class: Exception
Message: EOF Mark not found.
------------------------------------

One suggestion would be to add an OnException event to handle errors and display an elegant message to the user.

  • 2 weeks later...
  • 2 weeks later...
  • 1 month later...
Posted

Hello, 

Could you please provide some details? Which uniGUI version are you using, approximate file sizes you are trying to upload, what mobile device and browser, and also the value of your AjaxTimeout?

 

Posted

AjaxTimeOut: 240000
Version: 1.95.0.1592

Regarding the log, these are photos taken with a cell phone, and I can't determine the model/brand. After implementing the option to upload images to S3, I've been getting these errors every day. I don't know how to deal with this.

  • 4 weeks later...
Posted

One more thing: I changed the component to open the camera directly, eliminating access to the gallery and no longer experiencing errors.

However, my client complained that they need to access the gallery. Note: The error occurs with images coming from the gallery.

  • 3 weeks later...
Posted

Date: 30/09/2025 10:07:53
User: link.jd - Mobile
Agent: Mozilla/5.0 (iPhone; CPU iPhone OS 18_5 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/18.5 Mobile/15E148 Safari/604.1
Versão: 3.0.0.990
Navegador: safari
Navegador Versão: 18
OS: ios
SessionID: 1_GlCUTeLBpg111C442D4
Component: UnimFileUpload (TUnimFileUpload)
Parent: UnimFormAtendimentoVeiculoPrestadorM
LastAjaxEvent: upload
Class: Exception
Message: EOF Mark not found.
CallStack: [0137774E] uniFileUpload.TUniFileUploadHelper.HandleUpload (Line 1732, "uniFileUpload.pas" + 74)
[013743C6] uniFileUpload.TUniCustomFileUpload.HandleUpload (Line 504, "uniFileUpload.pas" + 0)
[0137443D] uniFileUpload.TUniCustomFileUpload.JSEventHandler (Line 521, "uniFileUpload.pas" + 3)
[00500BDD] uniGUIClasses.TUniComponent.DOHandleEvent (Line 2362, "uniGUIClasses.pas" + 1)
[00500D49] uniGUIClasses.TUniComponent.HandleEventIntercept (Line 2399, "uniGUIClasses.pas" + 27)
[00537D28] uniGUISessionManager.TUniSessionWorkerThread.ProcessEvent (Line 1579, "UniGUISessionManager.pas" + 18)
[00527BD7] uniGUIApplication.TUniGUISession.ProcessEventQueue (Line 1500, "uniGUIApplication.pas" + 12)
[00527D31] uniGUIApplication.TUniGUISession.ProcessEvents (Line 1532, "uniGUIApplication.pas" + 12)
[000C6F11] System.Variants.@VarClear$qqrr8TVarData
[000C6F19] System.Variants.@VarClr$qqrr8TVarData
[0126EB52] uniGUImJSForm.TUnimJSForm.DoShow (Line 317, "uniGUImJSForm.pas" + 1)
[004B38E2] uniGUIJSForm.TUniBaseJSForm.ShowModal (Line 1301, "uniGUIJSForm.pas" + 17)
[0046C30F] uniGUIForm.TUniBaseForm.ShowModal (Line 1649, "uniGUIForm.pas" + 1)
[016E7219] unimFileUpload.TUnimFileUpload.Execute (Line 247, "unimFileUpload.pas" + 56)
[018437DE] view.cadastro.atendimentoveiculoprestadorm.TUnimFormAtendimentoVeiculoPrestadorM.btnImagensClick (Line 352, "view.cadastro.atendimentoveiculoprestadorm.pas" + 7)
[00503A64] uniGUIClasses.

  • 1 month later...
Posted

Another failed attempt; instead of uploading the images directly, I've been storing them in a temp folder in the cache, but the error still occurs when uploading the images.

 

Date: 09/11/2025 12:30:23
User: link.jd - Mobile
Agent: Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/142.0.0.0 Mobile Safari/537.36
Versão: 3.0.0.1022
Navegador: chrome
Navegador Versão: 0
OS: android
SessionID: 3_xNYa9g9dd611201729D
Component: UnimFileUpload (TUnimFileUpload)
Parent: UnimFormGaleriaAtendimentoPrestadorM
LastAjaxEvent: upload
Class: Exception
Message: EOF Mark not found.
CallStack: [01C1F36A] uniFileUpload.TUniFileUploadHelper.HandleUpload (Line 1732, "uniFileUpload.pas" + 74)
[01C1BFE2] uniFileUpload.TUniCustomFileUpload.HandleUpload (Line 504, "uniFileUpload.pas" + 0)
[01C1C059] uniFileUpload.TUniCustomFileUpload.JSEventHandler (Line 521, "uniFileUpload.pas" + 3)
[00D91245] uniGUIClasses.TUniComponent.DOHandleEvent (Line 2362, "uniGUIClasses.pas" + 1)
[00D913B1] uniGUIClasses.TUniComponent.HandleEventIntercept (Line 2399, "uniGUIClasses.pas" + 27)
[00DC8390] uniGUISessionManager.TUniSessionWorkerThread.ProcessEvent (Line 1579, "UniGUISessionManager.pas" + 18)
[00DB823F] uniGUIApplication.TUniGUISession.ProcessEventQueue (Line 1500, "uniGUIApplication.pas" + 12)
[00DB8399] uniGUIApplication.TUniGUISession.ProcessEvents (Line 1532, "uniGUIApplication.pas" + 12)
[00956F21] System.Variants.@VarClear$qqrr8TVarData
[00956F29] System.Variants.@VarClr$qqrr8TVarData
[01B065CE] uniGUImJSForm.TUnimJSForm.DoShow (Line 317, "uniGUImJSForm.pas" + 1)
[00D43F4A] uniGUIJSForm.TUniBaseJSForm.ShowModal (Line 1301, "uniGUIJSForm.pas" + 17)
[00CFC977] uniGUIForm.TUniBaseForm.ShowModal (Line 1649, "uniGUIForm.pas" + 1)
[01F7D2E1] unimFileUpload.TUnimFileUpload.Execute (Line 247, "unimFileUpload.pas" + 56)
[020EA2F0] view.cadastro.galeriaatendimentoprestadorm.TUnimFormGaleriaAtendimentoPrestadorM.btnAcessoCameraClick (Line 151, "view.cadastro.galeriaatendimentoprestadorm.pas" + 0)
[00D940CC] uniGUIClasses.TUniControl.DoC

 

view.cadastro.galeriaatendimentoprestadorm.dfm view.cadastro.galeriaatendimentoprestadorm.pas

Posted

It's quite difficult to know for sure, but that screen is used to upload images; it's used on mobile phones, and they're not on Wi-Fi.

Regarding the sizes, they're images taken from the camera, which may or may not be in the gallery. I believe they upload about 5-10 images.

Posted

I was thinking, this also happens on the desktop version, however, I saw few logs, so we can imagine it could even be an internet outage; Brazil has a somewhat poor infrastructure.

Posted

I'll try to help you with this.

Errors like "EOF Mark not found" or "Error Status = 0" during upload are almost always due to (proxy/nginx/Cloudflare interruption, timeouts) and the file integrity arrived broken, hence the EOF error. It's rarely an image decoding issue; it's almost always a transport/upload integrity problem.

Do you use a reverse proxy? Nginx or Cloudflare?


nginx:

# tamanho e buffers
client_max_body_size 100m;
client_body_buffer_size 512k;

# evitar buffering em disco e problemas com HTTP/2 + chunked
proxy_http_version 1.1;
proxy_request_buffering off;
proxy_buffering off;

# timeouts folgados p/ redes móveis
proxy_read_timeout 300s;
proxy_send_timeout 300s;
send_timeout 300s;

# (opcional) logs mais verbosos p/ investigar corpo truncado
log_format bodydebug '$remote_addr - $request_time - $status - $body_bytes_sent - '
                     '$http_content_length - $upstream_status - $upstream_response_time';
access_log /var/log/nginx/access_bodydebug.log bodydebug;

cloudflare:
image.thumb.png.bcc45aa46936c0925927f474f362230f.png

You can also add a request log before it reaches your component; this helps identify the size. If the Content-Length is greater than what you receive (mobile), it's a truncation issue on the network/proxy.
 

procedure TUniServerModule.UniGUIServerModuleHTTPCommand(
  ARequestInfo: TIdHTTPRequestInfo; AResponseInfo: TIdHTTPResponseInfo;
  var Handled: Boolean);
var
  ct, lenStr: string;
  len: Integer;
begin
  // Log básico do upload [temporario para debug]
  if SameText(ARequestInfo.Command, 'POST') and
     ARequestInfo.ContentType.Contains('multipart/form-data') then
  begin
    ct := ARequestInfo.ContentType;
    len := ARequestInfo.ContentLength;
    lenStr := IntToStr(len);

    Logger.AddLog(Format('UPLOAD IN: CT=%s Len=%s UA=%s',
      [ct, lenStr, ARequestInfo.RawHeaders.Values['User-Agent']]));
  end;
end;

By default, it should always be the same size.

How to interpret:

If Content-Length is large (e.g., 8–12 MB) and you are writing fewer bytes (or OnCompleted comes with AStream=nil), it's truncation on the route (proxy/network).

If the size is small (100–300 KB) and it passes, the limits/timeout were the bottleneck.

 

Posted
On 5/17/2025 at 3:09 PM, picyka said:
procedure TUnimFormAtendimentoVeiculoPrestadorM.UnimFileUploadMultiCompleted(Sender: TObject; Files: TUniFileInfoArray);
begin
  if Length(Files) > 0 then
  begin
    try
      for var _File in Files do
      begin
        if (_File.Stream <> nil) and (_File.Stream.Size > 0) then
        begin
          var lFileName := _File.FileName;
          lFileName := TStringUtils.RemoveAcento(lFileName);

          Self.FClientImagem.Service<IServiceAnexo>.AnexarByTipoAwsS3(Self.FAtendimentoServico.AtendimentoVeiculo.Empresa.Id,
            UniMainModule.UserInfo.IdUsuario,
            lFileName,
            Self.FAtendimentoServico.AtendimentoVeiculo.ClassName, '',
            Self.FAtendimentoServico.AtendimentoVeiculo.Id,
            _File.Stream);

          var lAtendimento := Self.FControllerAtendimento.Find(Self.FAtendimentoServico.AtendimentoVeiculo.Id);

          if lAtendimento <> nil then
          begin
            Self.FControllerAtendimento.AddHistorico(lAtendimento,'ADD Imagem LINK: ' + lFileName,  _TIPO_HISTORICO_INTERNO);
            Self.FControllerAtendimento.Save(lAtendimento);
          end;
        end;
      end;
    except
      on E: EXDataOperationRequestException do
      begin
        TMessageUtils.Error(E.ErrorMessage);
        Exit;
      end;

      on E: Exception do
        TMessageUtils.Error(E.Message);
    end;
  end;
end;

This is my code, the error occurs, when taking an image from the gallery, I can't simulate it, I have no idea how this happens.

Improved code for logging the size.

 

procedure TUnimFormAtendimentoVeiculoPrestadorM.UnimFileUploadMultiCompleted(
  Sender: TObject; Files: TUniFileInfoArray);
begin
  if Length(Files) = 0 then
    Exit;

  for var F in Files do
  begin
    try
      // 1) Validar presença do stream
      if (F.Stream = nil) or (F.Stream.Size = 0) then
      begin
        TMessageUtils.Error(
          Format('Falha ao receber "%s". Tente novamente (rede/arquivo grande).',
                 [F.FileName]));
        Continue;
      end;

      // 2) Normalizar nome
      var LFileName := TStringUtils.RemoveAcento(F.FileName).Trim;
      if LFileName = '' then
        LFileName := 'arquivo';

      // 3) Copiar p/ MemoryStream e resetar posição
      var MS := TMemoryStream.Create;
      try
        F.Stream.Position := 0;
        MS.CopyFrom(F.Stream, 0);
        MS.Position := 0;

        // (Opcional) tamanho máximo defensivo (ex.: 50 MB)
        const MAX_BYTES = 50 * 1024 * 1024;
        if MS.Size > MAX_BYTES then
        begin
          TMessageUtils.Error(
            Format('Arquivo "%s" excede %d MB.', [LFileName, MAX_BYTES div 1024 div 1024]));
          Continue;
        end;

        // 4) Chamada de anexar (garanta que ela lê do Position atual)
        Self.FClientImagem.Service<IServiceAnexo>.AnexarByTipoAwsS3(
          Self.FAtendimentoServico.AtendimentoVeiculo.Empresa.Id,
          UniMainModule.UserInfo.IdUsuario,
          LFileName,
          Self.FAtendimentoServico.AtendimentoVeiculo.ClassName,
          '',
          Self.FAtendimentoServico.AtendimentoVeiculo.Id,
          MS // stream já posicionado no início
        );
      finally
        MS.Free;
      end;

      // 5) Histórico
      var LAt := Self.FControllerAtendimento.Find(
                    Self.FAtendimentoServico.AtendimentoVeiculo.Id);
      if LAt <> nil then
      begin
        Self.FControllerAtendimento.AddHistorico(
          LAt, 'ADD Imagem LINK: ' + LFileName, _TIPO_HISTORICO_INTERNO);
        Self.FControllerAtendimento.Save(LAt);
      end;

    except
      on E: EXDataOperationRequestException do
      begin
        TMessageUtils.Error(E.ErrorMessage);
        // Continua pros próximos arquivos
      end;
      on E: Exception do
      begin
        TMessageUtils.Error('Erro ao anexar: ' + E.Message);
      end;
    end;
  end;
end;

 

Posted
22 minutes ago, Marlon Nardi said:

I'll try to help you with this.

Errors like "EOF Mark not found" or "Error Status = 0" during upload are almost always due to (proxy/nginx/Cloudflare interruption, timeouts) and the file integrity arrived broken, hence the EOF error. It's rarely an image decoding issue; it's almost always a transport/upload integrity problem.

Do you use a reverse proxy? Nginx or Cloudflare?


nginx:

# tamanho e buffers
client_max_body_size 100m;
client_body_buffer_size 512k;

# evitar buffering em disco e problemas com HTTP/2 + chunked
proxy_http_version 1.1;
proxy_request_buffering off;
proxy_buffering off;

# timeouts folgados p/ redes móveis
proxy_read_timeout 300s;
proxy_send_timeout 300s;
send_timeout 300s;

# (opcional) logs mais verbosos p/ investigar corpo truncado
log_format bodydebug '$remote_addr - $request_time - $status - $body_bytes_sent - '
                     '$http_content_length - $upstream_status - $upstream_response_time';
access_log /var/log/nginx/access_bodydebug.log bodydebug;

cloudflare:
image.thumb.png.bcc45aa46936c0925927f474f362230f.png

You can also add a request log before it reaches your component; this helps identify the size. If the Content-Length is greater than what you receive (mobile), it's a truncation issue on the network/proxy.
 

procedure TUniServerModule.UniGUIServerModuleHTTPCommand(
  ARequestInfo: TIdHTTPRequestInfo; AResponseInfo: TIdHTTPResponseInfo;
  var Handled: Boolean);
var
  ct, lenStr: string;
  len: Integer;
begin
  // Log básico do upload [temporario para debug]
  if SameText(ARequestInfo.Command, 'POST') and
     ARequestInfo.ContentType.Contains('multipart/form-data') then
  begin
    ct := ARequestInfo.ContentType;
    len := ARequestInfo.ContentLength;
    lenStr := IntToStr(len);

    Logger.AddLog(Format('UPLOAD IN: CT=%s Len=%s UA=%s',
      [ct, lenStr, ARequestInfo.RawHeaders.Values['User-Agent']]));
  end;
end;

By default, it should always be the same size.

How to interpret:

If Content-Length is large (e.g., 8–12 MB) and you are writing fewer bytes (or OnCompleted comes with AStream=nil), it's truncation on the route (proxy/network).

If the size is small (100–300 KB) and it passes, the limits/timeout were the bottleneck.

 

I use Cloudflare, and my usage is focused on uploading images that the service provider takes at the service location.

So, they can upload several images from their gallery, but I believe it never exceeds 10. However, I have another checklist routine that allows only one image to be uploaded at a time, and even then, the error occurs there as well.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...