{"record":{"id":"4f64fb0eca4a1c3d","repo":"microsoft/playwright","slug":"cannot-set-buffer-larger-than-50mb-please-write-i","errorCode":null,"errorMessage":"Cannot set buffer larger than 50Mb, please write it to a file and pass its path instead.","messagePattern":"Cannot set buffer larger than 50Mb, please write it to a file and pass its path instead\\.","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/playwright-core/src/client/elementHandle.ts","lineNumber":320,"sourceCode":"      }, kNoTimeout), { internal: true });\n      for (let i = 0; i < files.length; i++) {\n        const writable = WritableStream.from(writableStreams[i]);\n        await stream.promises.pipeline(fs.createReadStream(files[i]), writable.stream());\n      }\n      return {\n        directoryStream: rootDir,\n        streams: localDirectory ? undefined : writableStreams,\n      };\n    }\n    return {\n      localPaths,\n      localDirectory,\n    };\n  }\n\n  const payloads = items as FilePayload[];\n  if (filePayloadExceedsSizeLimit(payloads))\n    throw new Error('Cannot set buffer larger than 50Mb, please write it to a file and pass its path instead.');\n  return { payloads };\n}\n\nexport function determineScreenshotType(options: { path?: string, type?: 'png' | 'jpeg' | 'webp' }): 'png' | 'jpeg' | 'webp' | undefined {\n  if (options.path) {\n    const mimeType = getMimeTypeForPath(options.path);\n    if (mimeType === 'image/png')\n      return 'png';\n    else if (mimeType === 'image/jpeg')\n      return 'jpeg';\n    else if (mimeType === 'image/webp')\n      return 'webp';\n    throw new Error(`path: unsupported mime type \"${mimeType}\"`);\n  }\n  return options.type;\n}\n","sourceCodeStart":302,"sourceCodeEnd":337,"githubUrl":"https://github.com/microsoft/playwright/blob/c8fc3bf8d31542d59b4d4d9eaab1df93ff541dc6/packages/playwright-core/src/client/elementHandle.ts#L302-L337","documentation":"Thrown by convertInputFiles when the in-memory payload branch is taken and filePayloadExceedsSizeLimit returns true. The limit is fileUploadSizeLimit = 50 * 1024 * 1024 (50 MiB), summed across every payload's buffer.byteLength. Buffers are sent inline over the protocol; large uploads must go through file paths so the server can stream them.","triggerScenarios":"Passing FilePayload objects whose combined buffer size is ≥ 50 MiB, e.g. setInputFiles([{ name: 'big.bin', buffer: hugeBuffer }]). The size guard rejects before any transfer.","commonSituations":"Reading large media/archives into memory and uploading as buffers; converting many files to payloads in a loop; pushing log/data dumps.","solutions":["Write the buffer to a temp file and pass its path instead: setInputFiles('/tmp/big.bin').","If multiple large files, pass their paths (paths are streamed, not buffered).","Compress or chunk the payload to stay under 50 MiB if a temp file is impossible."],"exampleFix":"// before\nconst buf = await fs.promises.readFile('/tmp/big.bin'); // > 50 MiB\nawait locator.setInputFiles({ name: 'big.bin', mimeType: 'application/octet-stream', buffer: buf });\n\n// after\nawait locator.setInputFiles('/tmp/big.bin');","handlingStrategy":"validation","validationCode":"const LIMIT = 50 * 1024 * 1024; // matches fileUploadSizeLimit\nfunction totalPayloadSize(payloads) {\n  return payloads.reduce((n, p) => n + (p.buffer ? p.buffer.byteLength : 0), 0);\n}\nfunction assertUnderLimit(payloads) {\n  if (totalPayloadSize(payloads) >= LIMIT)\n    throw new Error('Combined buffer size ≥ 50 MiB; write to temp files and pass paths instead.');\n}","typeGuard":"import { statSync } from 'node:fs';\n// Prefer path-based input for large files — paths bypass the 50 MiB inline limit.\nfunction isLargeFile(p: string): boolean { try { return statSync(p).size >= 50 * 1024 * 1024; } catch { return false; } }","tryCatchPattern":null,"preventionTips":["Default to file paths for uploads; reserve buffers for small in-memory data.","Sum buffer sizes before assembling the payload list.","Write oversized buffers to a temp file with fs.promises.writeFile."],"tags":["file-upload","limits","input-files","memory"],"backgroundTag":null,"analyzedSha":"c8fc3bf8d31542d59b4d4d9eaab1df93ff541dc6","analyzedAt":"2026-08-12T07:26:36.950Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}