question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

The first part of this would be a class that just implements taking a files/data dict, and returning the byte-wise multipart content, plus the Content-Type header.

Places to start with this include urllib3, and the requests-toolbelt streaming multipart encoder.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
florimondmancacommented, Jun 15, 2020

Sure, so I think you need to split up between data=... (for operations and map) and files=... (for doc.pdf), something like this…

data = {
    "operations": json.dumps(gql_query),
    "map": """{
        "file": ["variables.input"]
    }""",
}

files = {
    "file": ("doc.pdf", open("doc.pdf", "rb"), "application/pdf"),
}

response = httpx.post(..., data=data, files=files)

The multipart encoding occurs whenever files=... is passed and non-empty, so in this case it will use whatever is in data as additional fields in the multipart form data.

This behavior is actually not crystal clear in the docs I believe, could probably use a “You can also add additional fields by passing data=...” in Sending Multipart Form Uploads.

1reaction
tomchristiecommented, Jun 15, 2020

There is a convoluted request that I only managed to send with MultipartEncoder

You’d need to be providing more details about exactly what you’re not able to do with httpx’s multiparty support in order for us to be able to help at all.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Uploading and copying objects using multipart upload
Multipart upload allows you to upload a single object as a set of parts. Each part is a contiguous portion of the object's...
Read more >
In Asp.Net Core, how can I get the multipart/form-data from the ...
I created a helper method that grabs both files and form values. public static List<FileModel> GetFileModelsFromRequest(HttpRequest request) { ...
Read more >
chikien276/MultipartHelper: AspNetCore multipart upload file ...
AspNetCore multipart upload file helper. Contribute to chikien276/MultipartHelper development by creating an account on GitHub.
Read more >
Multipart Class | Microsoft Learn
Helper for submitting multipart data This follows the Network Working Group's RFC on multipart/form-data posting format: ...
Read more >
Multipart Form-Data Upload - Help Center - Azuqua
Run nc -l -p 8000 to create a netcat server listening on localhost:8000. This will display the body of our multipart request. If...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found