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

221 222 223 accept and send formdata and files #226

Merged
merged 1 commit into from
Oct 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions samples/steps/http-post.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@ post_step:
* `contentType` - specifies the contenttype to use, currently allowed values:
* `"plaintext"` - uses field `plaintext` and mediaType 'text/plain'
* `"formdata"`
- if any field names start with `file:`, that field is sent as a file with
filename field name without `file:` part and mediatype "multipart/form-data";
- if a key start with `file:`, that field content is sent as a file on a
field named as the second part of the key and original filename as third part of
the key, for example `file:projectdata:Project.csv`, and mediatype "multipart/form-data";
- otherwise maps `body` as url-encoded form and mediatype 'application/x-www-form-urlencoded'
as
* If left empty, `body` is posted as JSON and 'application/json' is used as mediatype.
Expand Down Expand Up @@ -89,7 +90,7 @@ post_step:
contentType: formdata
body:
description: "Requested file"
file:requested.txt: >
file:fieldname:requested.txt: >
This is the required content
formatted as YAML multiline string
result: the_message
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/ee/buerokratt/ruuter/helper/HttpHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,9 @@ public ResponseEntity<Object> doMethod(HttpMethod method,
for (Map.Entry<String, Object> e : body.entrySet()) {
if (e.getKey().startsWith("file:")) {
byte[] bytes = ((String) e.getValue()).getBytes();
String filename= e.getKey().replace("file:", "");
builder.part(e.getKey(), new ByteArrayResource(bytes)).filename(filename);
String fieldname = e.getKey().split(":")[1];
String filename = e.getKey().split(":")[2];
builder.part(fieldname, new ByteArrayResource(bytes)).filename(filename);
}
else {
builder.part(e.getKey(), e.getValue());
Expand Down