0

The new V1.0.2 has new capabilities to upload attachments to a domino document. My upload code is successful as long a I use files <= 48KB. As soon as I try to upload a larger file, the upload takes place, in the domino document I find an attachment with the right size - but the file is corrupt!

Here's my code (corresponds to example code from appdev pack documentation for larger files):

for (var x = 0; x < files["tskFile"].length; x++) {          
          let sFilename = files["tskFile"][x].originalname;         
          let sPath = files["tskFile"][x].path;
          let buffer = fs.readFileSync(sPath);
          const writable = await db.bulkCreateAttachmentStream({});
          writable.on('error', e => {
            // An error occurred and the stream is closed
            console.error("Error on write ", e)
          });
          writable.on('response', response => {
            // The attachment content was written to the document and a
            // response has arrived from the server
            console.log(">> File " + sFilename + " saved to doc ")
          });
          let error;         
          // Write the image in n chunks
          let offset = 0;
          const writeRemaining = () => {
            if (error) {
              return;
            }
            let draining = true;
            while (offset < buffer.length && draining) {
              const remainingBytes = buffer.length - offset;
              let chunkSize = 16 * 1024;
              if (remainingBytes < chunkSize) {
                chunkSize = remainingBytes;
              }                            
              const chunk = new Uint8Array(
                buffer.slice(offset, offset + chunkSize),
              );
              draining = writable.write(chunk);              
              offset += chunkSize;
            }

            if (offset < buffer.length) {
              // Buffer is not draining. Write some more once it drains.              
              writable.once('drain', writeRemaining);
            } else {
              writable.end();                           
            }
          };          
          writable.file({
            unid: unid,
            fileName: sFilename,
          });
          writeRemaining();
        } // end forall attachments

Here are my notes.ini variables for my server:

PROTON_MAX_WRITE_ATTACHMENT_MB=30, 
PROTON_MAX_ATTACHMENT_CHUNK_KB=50, 
PROTON_MIN_ATTACHMENT_CHUNK_KB=8

My error or bug in AppDevPack? Did anyone try this new feature?

Bill P
  • 3,622
  • 10
  • 20
  • 32

2 Answers2

0

I am able to reproduce a similar issue with Proton on 64-bit Windows. I cannot reproduce with Proton running on Linux. I am using different client code than you are, but I'm 99% sure this is a Windows-only bug in Proton. We will update this answer when we have more information. Meanwhile, are you able to try Proton on Linux?

Dave Delay
  • 1,292
  • 8
  • 12
  • Thanks a lot. We have a Linux Installation for Proton, but for the moment it has not been updated to AppDevPack 1.0.2. I have to ask my admin next week if an update will be possible - Linux is not really my universe.... – Gabriele Chakir Oct 01 '19 at 04:59
  • I tried it on Linux today, same code: it works! No document corruption for proton on Linux... so I wait for a fix for windows ;-) – Gabriele Chakir Oct 08 '19 at 13:30
0

We have found a fix and it will be included in our next drop. Thank you for this report!

ddumont
  • 583
  • 3
  • 14