Skip to content

Commit

Permalink
Merge pull request #226 from buerokratt/221-222-223-accept-and-send-f…
Browse files Browse the repository at this point in the history
…ormdata-and-files

223 POST files
  • Loading branch information
RayDNoper authored Oct 12, 2023
2 parents bce994d + b80f6e2 commit 68ce313
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
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

0 comments on commit 68ce313

Please sign in to comment.