playwright-python icon indicating copy to clipboard operation
playwright-python copied to clipboard

[Bug]: cant get content of upload file

Open daniera3 opened this issue 6 months ago • 4 comments

Version

latest

Steps to reproduce

Image

cant get content of file uploaded

Expected behavior

get asdasdasd in post_data

Actual behavior

in pyptteer i can get this content with

    await cdp.send("Network.enable", {
        # Buffer up to 10 MB of POST/PUT data
        "maxPostDataSize": 0
    })
    async def on_request_will_be_sent(params):
        try:
            req = params["request"]
            if req.get("method") == "PUT" and "/api/file/raw" in req.get("url", ""):
                request_id = params["requestId"]
                # Ask Chrome: “Please give me the POST/PUT payload that you buffered.”
                resp = await cdp.send(
                    "Network.getRequestPostData",
                    {"requestId": request_id}
                )
                body = resp.get("postData", None)
                print("→ Caught PUT to /api/file/raw via Network:")
                print("   • request.postData →", body)
                # If you want bytes instead of a string, do:
                # raw_bytes = body.encode("utf-8")
                # print("   • as bytes:", raw_bytes)
        except Exception as e:
            # If "No post data available" still shows up, check that `maxPostDataSize` was set early enough.
            print("ERROR in on_request_will_be_sent:", e)

    cdp.on("Network.requestWillBeSent", lambda event: asyncio.create_task(on_request_will_be_sent(event)))

Additional context

No response

Environment

- Operating System: [Ubuntu 22.04]
- CPU: [arm64]
- Browser: [All, Chromium, Firefox, WebKit]
- Python Version: [3.12]
- Other info:

daniera3 avatar Jun 03 '25 12:06 daniera3