Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why does it prompt that the file does not exist when I use the post method of the APIRequestContext object to upload a form file? #2702

Open
1 task done
1219213291 opened this issue Dec 30, 2024 · 1 comment

Comments

@1219213291
Copy link

1219213291 commented Dec 30, 2024

Please do not submit this issue.

  • I understand
@1219213291
Copy link
Author

Hello guys!
I am trying to upload a form file using the post method of the APIRequestContext object, just like in the official documentation.

api_request_context.post(
  "https://example.com/api/uploadScript'",
  multipart={
    "fileField": {
      "name": "f.js",
      "mimeType": "text/javascript",
      "buffer": b"console.log(2022);",
    },
  })

Here is my test code snippet:

api_request_context.post(
    url=https://localhost/api/upload'",
    multipart={
        "files": {
            "name": "Changed_FROR.xlsx",
            "mimeType": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
            "buffer": open(file_path,"rb").read(),
        },
        'systemId': 'arg1',
        'code': 'test_code'
    }

).json()

My backend service is unable to retrieve the corresponding file and prompts that the uploaded file cannot be empty.
Because I need to call some API interfaces before running my automated test cases to quickly and reliably complete the setup operations, in order to shorten the runtime. So this is a very efficient and commonly used operation. I don't know if there's an issue with my usage or if this is a bug, and I hope someone can help clarify. Otherwise, I'll have to use the request library as a substitute.

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

No branches or pull requests

1 participant