Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Bootstrap4 fileinput bug
#1
Im use iwbootstrap4 + Bootstrap File Input library for upload files:

Code:
procedure TFrameProductPicture.IWBS4File1CustomRestEvents0RestEvent(
  aApplication: TIWApplication; aRequest: THttpRequest; aReply: THttpReply;
  aParams: TStrings);
var
FileUpload: THttpFile;
begin
  if aRequest.Files.Count > 0 then
   begin
    FileUpload := THttpFile( aRequest.Files[ aRequest.Files.Count - 1 ] );

    FPictureFile := IWServerController.ContentPath +
                    UPLOAD_FOLDER + '\' +
                    TPath.GetGUIDFileName.ToLower +
                    ExtractFileExt( FileUpload.FileName );

    FileUpload.SaveToFile( FPictureFile );
   end;

  aReply.WriteString('{"id": "1"}');
end;

Most JPG files load normally, but some JPG files, as well as ALL PNG files get corrupted after loading (only part of the image is loaded), here is an example of files BEFORE and AFTER uploading to the server. What could be the reason ?

IW version: 15.1.19

   

.png   2bd0d041e0ef4632bf8e55d21ebc70a8.png (Size: 252.03 KB / Downloads: 8)
Reply
#2
I found out that the data of the input file and the file stored on the server differ by one byte at approximately the same address, then the file structure is saved.
I have attached examples of comparison of three files downloaded not by the server, on top is the original file, on the bottom is the file after loading. I circled the places of difference in red (one byte is always lost in the saved file).
I still have not figured out what is causing this.


   
   
   
Reply
#3
Hi,

I have the same problem with IW v15.1.20
I can't upload multiple files. Only a few files are uploaded.

But I do this:
If I set IWBS4File1 > CustomRestEvents > uploadUrl > ParseFileUpload to False
All files will be uploaded, but I have to manually parse files.
Reply
#4
I noticed that in StandAlone Server mode everything works fine, the problem only occurs in HTTPSys mode.
Reply
#5
(04-19-2020, 09:21 PM)TPiotr Wrote: Hi,

I have the same problem with IW v15.1.20
I can't upload multiple files. Only a few files are uploaded.

But I do this:
If I set IWBS4File1 > CustomRestEvents > uploadUrl > ParseFileUpload to False
All files will be uploaded, but I have to manually parse files.

How you get a PostStream for parsing ? My aRequest: THttpRequest don`t have PostStream parametr.
Reply
#6
Code:
procedure TAppUpload.IWBS4File1CustomRestEvents0RestEvent(
  aApplication: TIWApplication; aRequest: THttpRequest; aReply: THttpReply;
  aParams: TStrings);
var i: integer; AStream: TMemoryStream;
begin

for i := 0 to aRequest.Files.Count-1 do
begin

// THttpFile(aRequest.Files[i]).SaveToFile(ExtractFilePath(ParamStr(0))+'Data\'+aRequest.Files[i].FileName, True);
  AStream := TMemoryStream.Create;
  try
   THttpFile(aRequest.Files[i]).SaveToStream(AStream);
   AStream.Position := 0;
   AStream.SaveToFile(ExtractFilePath(ParamStr(0))+'Data\'+aRequest.Files[i].FileName); // Correct FileName can only be read manually from the stream
   (...)

  finally
   AStream.Free;
  end;

end;
aReply.WriteString('{"id": "1"}');
end;


You get all files when you set IWBS4File1 > CustomRestEvents > uploadUrl > ParseFileUpload to False

Stream looks like this:

------WebKitFormBoundaryQm9CpCSSrHXo0r3p
Content-Disposition: form-data; name="IWBS4FILE1[]"; filename="TestFile.png"
Content-Type: image/png

‰PNG
(...)
------WebKitFormBoundaryQm9CpCSSrHXo0r3p
Content-Disposition: form-data; name="file_id"

2
------WebKitFormBoundaryQm9CpCSSrHXo0r3p--
Reply
#7
I know what the stream looks like, but I don't know how to get it:
If I set ParseFileUpload to False, then the aRequest.Files.Count will always be 0.
Reply
#8
I always have aRequest.Files.Count := 1
CustomRestEvents0RestEvent executes every uploaded file.

My code from DFM:

Code:
object IWBS4File1: TIWBS4File
    Left = 331
    Top = 144
    Width = 161
    Height = 33
    CustomAsyncEvents = <
      item
        EventName = 'fileuploaded'
        OnAsyncEvent = IWBS4File1CustomAsyncEvents0AsyncEvent
      end>
    CustomRestEvents = <
      item
        EventName = 'uploadUrl'
        OnRestEvent = IWBS4File1CustomRestEvents0RestEvent
        ParseFileUpload = False
      end>
    Script.Strings = (

        '$("#{%htmlname%}").fileinput({uploadUrl: "{%uploadUrl%}", langua' +
        'ge: "pl", maxFileSize: 2097152000, showRemove: false, showPrevie' +
        'w: false, allowedPreviewTypes: null});'

        '$("#{%htmlname%}").off("fileuploaded").on("fileuploaded", functi' +
        'on() {{%fileuploaded%}});')
    Multiple = True
  end
Reply
#9
(04-20-2020, 10:58 AM)TPiotr Wrote: I always have aRequest.Files.Count := 1
CustomRestEvents0RestEvent executes every uploaded file.

My code from DFM:

Code:
object IWBS4File1: TIWBS4File
    Left = 331
    Top = 144
    Width = 161
    Height = 33
    CustomAsyncEvents = <
      item
        EventName = 'fileuploaded'
        OnAsyncEvent = IWBS4File1CustomAsyncEvents0AsyncEvent
      end>
    CustomRestEvents = <
      item
        EventName = 'uploadUrl'
        OnRestEvent = IWBS4File1CustomRestEvents0RestEvent
        ParseFileUpload = False
      end>
    Script.Strings = (

        '$("#{%htmlname%}").fileinput({uploadUrl: "{%uploadUrl%}", langua' +
        'ge: "pl", maxFileSize: 2097152000, showRemove: false, showPrevie' +
        'w: false, allowedPreviewTypes: null});'

        '$("#{%htmlname%}").off("fileuploaded").on("fileuploaded", functi' +
        'on() {{%fileuploaded%}});')
    Multiple = True
  end

Which apptype are you using SA (IWStart) or HTTPSys(IWStartHSys)  ?
Reply
#10
I'm using IWStandAloneServer.

It's important to add:

Code:
implementation

{$R *.dfm}
uses IWBS4RestServer;

initialization
  IWBS4RegisterRestServerHandler;
end.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)