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
How do we create a pact for Multipart file upload using POST #123
Comments
Pact currently only supports text formats. If you need to post a binary body, we could implement it but it would have to be base64 encoded in the pact file. The other option is with mime multipart bodies (like from a FORM POST with a file selection). You will have to set the content type to include the boundary marker in the body, i.e.
The |
Thanks! I'll explore and get back to you. |
We are in a similar situation where we would like to use Pact for a service provider accepting mime multipart bodies. Support for multipart matching would definitely be useful. |
We went for the full string body matching as a workaround, however we are a bit limited by the fact that there are no regex request matching rules for string bodies. Given that the MIME multipart boundary string is usually randomly generated, it is a bit hard to match exactly... Any other ideas? Thank you. |
I have been thinking about this, and it does not make sense to have matchers in this case. What you probably want to do is confirm that a file was included with the body, i.e., the contents are not empty. Are you using the JUnit DSL? |
Yes, we're using the JUnit DSL. The provider service accepts POST multipart/form-data, with multiple parts being sent, one of which is the uploaded file. Ideally, we should be able to match/verify each part independently. For the uploaded file part, simply confirming that a file was included should be OK. |
any pointers to example of file upload? |
Can we have this enhancement implemented please? |
I've managed to do this with a pact between JS and JVM. The interaction on the consumer side is setup as {
"method": "POST",
"path": "/promotion-groups/a_group_id/product-promotions",
"headers": {
"Content-Type": "multipart/form-data; boundary=----WebKitFormBoundary1bvPHrYmtx0UNv2e"
},
"body": "------WebKitFormBoundary1bvPHrYmtx0UNv2e\r\nContent-Disposition: form-data; name=\"file\"; filename=\"476.csv\"\r\nContent-Type: text/csv\r\n\r\ndata\r\n------WebKitFormBoundary1bvPHrYmtx0UNv2e--\r\n"
} where |
Support for matching multi-part file uploads has now been added. |
We have a scenario where we need to upload a file using post. Is there an option in pact jvm to pass file input in .body()? Is there an example? How do we go about it?
The text was updated successfully, but these errors were encountered: