Skip to content

Fix uploading temporary files in blocks and the extension dot - #41

Open
Torquem wants to merge 2 commits into
masterfrom
topic/Fix-legacy-upload-in-blocks
Open

Torquem wants to merge 2 commits into
masterfrom
topic/Fix-legacy-upload-in-blocks

Conversation

@Torquem

@Torquem Torquem commented Oct 29, 2026

Copy link
Copy Markdown
Collaborator

Summary

Fixes bugs in the upload-ID block upload and in how file names are split into a title and an extension.

Block uploads (upload IDs)

  • The last block now contains only its own data. Before, the whole buffer was sent, so the uploaded file was padded with leftover data from the previous block.
  • The block count is now rounded up. When the file size divided evenly by the block size, the count was one too high, so MFWS never saw the last block and didn't commit the upload.
  • New UploadTemporaryFileBlock[Async] overloads take the block size, so a shorter last block can be uploaded. The existing overloads call them with the block's own length.
  • The block methods now reject an offset that isn't at a block boundary and a block larger than the block size. Before, such a block could be written at the wrong position without any error.
  • Each block is read fully from the stream.

File names

  • The file name is split once into a title and an extension without the dot, which is what M-Files expects (GetFileTitle, GetFileExtension). These replace the separate dot removal in UploadFiles and UploadTemporaryFileBlockBegin(FileInfo), and fix UploadTemporaryFileInBlocks, which sent .pdf instead of pdf.
  • UploadFiles no longer throws for a file without an extension; it returns an empty extension.
  • UploadTemporaryFileInBlocks now returns the title, extension and size along with the upload ID, so the result can be used to create an object. Before, it returned the last block's response, which had no title or extension.

Tests

  • New tests cover the short last block, a size that divides evenly, a file smaller than one block, the block-size checks, and file names with and without extensions.
  • The upload tests now close test.txt after creating it. Before this, 10 tests failed on a clean run.

Testing

  • All 280 unit tests pass from a clean state (test.txt deleted).
  • Not yet tested against a live MFWS.

Note

This conflicts with #40 (CFO-1997) in the block loop of UploadTemporaryFileInBlocksAsync. Whichever merges second needs to resolve it.

🤖 Generated with Claude Code

Jari Siikarla and others added 2 commits October 29, 2026 12:06
Blocks identified by upload IDs:
- Send only the data of the last block instead of the whole buffer, which
  padded the uploaded file with leftover data from the previous block.
- Round the number of blocks up. A size that divided evenly by the block
  size gave one block too many, so MFWS never saw the last block.
- Add UploadTemporaryFileBlock[Async] overloads that take the block size,
  so a shorter last block can be uploaded. Reject offsets that are not at
  a block boundary and blocks larger than the block size.
- Read each block fully from the stream.

File names:
- Parse the file name once into a title and an extension without the dot
  (GetFileTitle, GetFileExtension), as M-Files expects. Replaces the
  separate dot removal in UploadFiles and UploadTemporaryFileBlockBegin,
  and the dotted extension in UploadTemporaryFileInBlocks. UploadFiles no
  longer throws for a file without an extension.
- UploadTemporaryFileInBlocks returns the title, extension and size with
  the upload ID, instead of the last block response which had neither a
  title nor an extension.

Tests: close test.txt after creating it, which made the upload tests
fail on a clean run.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
NuGet trusted publishing
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants