{"record":{"id":"7245c327e3e84c4f","repo":"Dokploy/dokploy","slug":"bad-request-7245c3","errorCode":"BAD_REQUEST","errorMessage":"Invalid file provided","messagePattern":"Invalid file provided","errorType":"exception","errorClass":"TRPCError","httpStatus":400,"severity":"error","filePath":"apps/dokploy/server/api/routers/docker.ts","lineNumber":320,"sourceCode":"\t\t\t\t\tthrow new TRPCError({ code: \"UNAUTHORIZED\" });\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn await getServiceContainersByAppName(input.appName, input.serverId);\n\t\t}),\n\n\tuploadFileToContainer: withPermission(\"docker\", \"read\")\n\t\t.input(uploadFileToContainerSchema)\n\t\t.mutation(async ({ input, ctx }) => {\n\t\t\tif (input.serverId) {\n\t\t\t\tconst server = await findServerById(input.serverId);\n\t\t\t\tif (server.organizationId !== ctx.session?.activeOrganizationId) {\n\t\t\t\t\tthrow new TRPCError({ code: \"UNAUTHORIZED\" });\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst file = input.file;\n\t\t\tif (!(file instanceof File)) {\n\t\t\t\tthrow new TRPCError({\n\t\t\t\t\tcode: \"BAD_REQUEST\",\n\t\t\t\t\tmessage: \"Invalid file provided\",\n\t\t\t\t});\n\t\t\t}\n\n\t\t\t// Convert File to Buffer\n\t\t\tconst arrayBuffer = await file.arrayBuffer();\n\t\t\tconst fileBuffer = Buffer.from(arrayBuffer);\n\n\t\t\tawait uploadFileToContainer(\n\t\t\t\tinput.containerId,\n\t\t\t\tfileBuffer,\n\t\t\t\tfile.name,\n\t\t\t\tinput.destinationPath,\n\t\t\t\tinput.serverId || null,\n\t\t\t);\n\n\t\t\treturn { success: true, message: \"File uploaded successfully\" };","sourceCodeStart":302,"sourceCodeEnd":338,"githubUrl":"https://github.com/Dokploy/dokploy/blob/546686ea3587f12ec5652217dedd9f7960fb6d15/apps/dokploy/server/api/routers/docker.ts#L302-L338","documentation":"After the tenant check passes, uploadFileToContainer validates that input.file is a DOM File instance. When the tRPC File input fails to arrive as File (e.g. malformed multipart from a custom client, plain object from a JSON payload, or a Node Buffer), it throws BAD_REQUEST 'Invalid file provided'. This is input-shape validation, not a permissions issue.","triggerScenarios":"Calling docker.uploadFileToContainer where input.file is not a File — e.g. sending { file: { name, content } } via JSON, or a client/transport version that does not encode the file as multipart File data.","commonSituations":"Custom scripts hitting the tRPC endpoint with fetch and forgetting FormData; browser polyfill differences; proxy stripping multipart boundaries.","solutions":["Send the mutation using FormData so the file arrives as a real File instance (dokploy's own client does this)","If calling programmatically, construct a File/Blob: new File([bytes], 'name') and pass it as the file input","Verify no middleware or serialization is converting the File to a plain object"],"exampleFix":"// before (fails: plain JSON body)\nawait trpc.docker.uploadFileToContainer.mutate({\n  containerId, path: '/tmp', file: { name: 'a.txt', content: 'hi' }, serverId,\n});\n\n// after (File instance)\nconst file = new File([new Blob(['hi'])], 'a.txt', { type: 'text/plain' });\nawait trpc.docker.uploadFileToContainer.mutate({\n  containerId, path: '/tmp', file, serverId,\n});","handlingStrategy":"type-guard","validationCode":"if (typeof file === 'undefined' || !(file instanceof File)) {\n  file = new File([new Blob([data])], filename);\n}","typeGuard":"const isFile = (f: unknown): f is File =>\n  typeof File !== 'undefined' && f instanceof File;","tryCatchPattern":"try {\n  await trpc.docker.uploadFileToContainer.mutate({ ...input, file });\n} catch (e) {\n  if (e instanceof TRPCClientError && e.message === 'Invalid file provided') {\n    // rebuild the file as a real File and retry\n  }\n}","preventionTips":["Always upload via FormData/File, never JSON-encode file payloads","Run the instanceof File guard before calling the mutation"],"tags":["trpc","dokploy","input-validation","file-upload","bad-request"],"backgroundTag":"request-body-validation-failed","analyzedSha":"546686ea3587f12ec5652217dedd9f7960fb6d15","analyzedAt":"2026-08-27T05:18:58.095Z","schemaVersion":2},"datasetVersion":"2026-08-27T08:17:20.692Z"}