Skip to content

File upload data is truncated via <form> tag on Windows  #365

@tako774

Description

@tako774

Step To Reproduce / Observed behavior

I am trying to upload an image file using Playwright for Ruby (playwright-ruby-client) with a standard HTML form (enctype="multipart/form-data").
Server uses PHP 7.4.33 (Pukiwiki 1.5.2).

The upload appears to succeed, but the uploaded file on the server side is corrupted:

  • Only the first 594 bytes (0x252 bytes) of the original file are received.
  • The rest of the file is missing.
    This happens consistently, even with small files (e.g. ~38KB PNG).

The same image file, when uploaded manually via a normal browser, is uploaded correctly.

Also, when running the same logic using Playwright TypeScript, the upload works correctly and the full file is transmitted. This suggests a bug specific to playwright-ruby-client, maybe.

Example Ruby code (simplified):

# file set with file chooser
chooser = page.expect_file_chooser do
  page.locator('input[type=file]').first.click
end
chooser.set_files(file_path)
# wait for set file
page.wait_for_timeout(500)
# submit
page.locator('input[type="submit"]').first.click

Target form HTML (text omitted):

<div id="body"><form enctype="multipart/form-data" action="./" method="post">
<div><input type="hidden" name="encode_hint" value=""></div>
 <div>
  <input type="hidden" name="plugin" value="attach">
  <input type="hidden" name="pcmd" value="post">
  <input type="hidden" name="refer" value="wiki_page_name">
  <input type="hidden" name="max_file_size" value="1048576">
  <label for="_p_attach_file">添付ファイル:</label> <input type="file" name="attach_file" id="_p_attach_file" size="30"> 
  <input type="submit" value="アップロード">
 </div>
</form></div>

Typescrpt (successful code):

// file set with file chooser
const [fileChooser] = await Promise.all([
  page.waitForEvent('filechooser'),
  page.locator('input[type="file"]').first().click(),
]);
await fileChooser.setFiles(filePath);
// wait for set file
await page.waitForTimeout(500);
// submit
page.locator('input[type="submit"]').first().click()

I also tried:

  • Adding longer waits (sleep, wait_for_timeout)
  • Using form.submit() via page.evaluate
  • Waiting for navigation / response
  • Using other brosers managed by playwright (chromium/firefox/webkit)

But the result is always the same: only the first 594 bytes are uploaded.

Expected behavior

The full file should be uploaded without truncation, identical to manual browser upload and Playwright TypeScript behavior using setFiles.

Environment

  • OS: Windows11
  • ruby 3.3.8 (2025-04-09 revision b200bad6cd) [x64-mingw-ucrt]
  • playwright-ruby-client: 1.5.7.1
  • playwright version: 1.5.7
  • typescript: 5.9.3

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions