Uploading attachments in Bulk - Limitation

mysamzamysamza Member Posts: 66
Brief;

I am uploading files in bulk to our custom table's headers and I am getting the following error;
Upload did not complete within the 65 seconds time limit.


The maximum file size is 350 MB.
If the file contains an image, consider reducing the size or quality of the image before uploading. If the file is an archive, consider splitting this into smaller archives if these can be uploaded individually. For other large files, consider linking to the file on an external document repository instead.

Specs;

Business Central (SaaS)
Version: W1 18.4 (Platform 18.0.28593.30086 + Application 18.4.28601.29160)

Details;
I have created Header, Lines, and a table to store attachments.
a)Manufacturing Job Header
b)Manufacturing Job Lines
c)Manufacturing Attachments

I have Header and Lines data uploaded and now I have to upload attachments.

Taking hints from the logic written on Inventory Setup's -> Import Item Pictures

I wrote the following code;
procedure LoadZIPFile(ZipFileName: Text; var TotalCount: Integer; ReplaceMode: Boolean): Text
    var
        Item: Record Item;
        FileMgt: Codeunit "File Management";
        DataCompression: Codeunit "Data Compression";
        TempBlob: Codeunit "Temp Blob";
        Window: Dialog;
        EntryList: List of [Text];
        EntryListKey: Text;
        ServerFile: File;
        InStream1: InStream;
        EntryOutStream: OutStream;
        EntryInStream: InStream;
        ServerFileOpened: Boolean;
        Length: Integer;
        Variant_No: Text;
        Rec_MyDocumentAttachment: Record "My Document Attachment";
        rec_DocuUpload: Record "Look Up Doc Attach";
        OutS: OutStream;
        "File Name_L": text;
        "File Extesion_L": Text;
        "File Size (KB)_L": Integer;
        Item_L: Text;
    begin
        rec_DocuUpload.Reset();
        Clear(rec_DocuUpload);

        if not UploadIntoStream('Variant ZIP Files', '', 'Zip Files|*.zip', ZipFileName, InStream1) then
            Error('');

        DataCompression.OpenZipArchive(InStream1, false);
        DataCompression.GetEntryList(EntryList);

        Window.Open('#1##############################');

        TotalCount := 0;
        DeleteAll();
        foreach EntryListKey in EntryList do begin
            Init();
            "File Name_L" := CopyStr(FileMgt.GetFileNameWithoutExtension(EntryListKey), 1, MaxStrLen(Rec."File Name"));
            "File Extesion_L" := CopyStr(FileMgt.GetExtension(EntryListKey), 1, MaxStrLen(Rec."File Extension"));
            TempBlob.CreateOutStream(EntryOutStream);
            DataCompression.ExtractEntry(EntryListKey, EntryOutStream, Length);
            TempBlob.CreateInStream(EntryInStream);
 
            "File Size (KB)_L" := Length;
            TotalCount += 1;
            rec_DocuUpload.Reset();
            Clear(rec_DocuUpload);
            rec_DocuUpload.SetCurrentKey(rec_DocuUpload.File_Name);
            rec_DocuUpload.SetRange(Transaction_Type, rec_DocuUpload.Transaction_Type::"Purchase Order");
            rec_DocuUpload.SetRange(File_Name, "File Name_L");
            if rec_DocuUpload.FindFirst() then
                Variant_No := rec_DocuUpload.Document_No;

            Clear(Rec_MyDocumentAttachment);
            Rec_MyDocumentAttachment.Init();
            Rec_MyDocumentAttachment.Validate("Table ID", 50029);
            Rec_MyDocumentAttachment.Validate("Document Type", rec."Document Type"::"Purchase Order");
            Rec_MyDocumentAttachment.Validate("No.", Variant_No);
            Rec_MyDocumentAttachment.Validate("File Name", "File Name_L");
            Rec_MyDocumentAttachment.Validate("File Extension", "File Extesion_L");
            Rec_MyDocumentAttachment.Validate("File Size (KB)", "File Size (KB)_L");
            Rec_MyDocumentAttachment.FileBlob.CreateOutStream(Outs);
            CopyStream(OutS, EntryInStream);
            Rec_MyDocumentAttachment.Insert(true);
            Commit();
        end;

        DataCompression.CloseZipArchive;
        Window.Close;


        exit(ZipFileName);
    end;
Sign In or Register to comment.