Skip to content

Commit

Permalink
Allow a filename to be provided so that it overrides the name of the …
Browse files Browse the repository at this point in the history
…passed file.
  • Loading branch information
Lee Painter committed Sep 30, 2022
1 parent 380254e commit 3cbb411
Showing 1 changed file with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ private Request generateJsonPOSTRequest(String url, String json) {

url = HypersocketUtils.encodeURIPath(url);

RequestBody body = RequestBody.create(JSON, json);
RequestBody body = RequestBody.create(json, JSON);

Request.Builder request = new Request.Builder()
.url(buildUrl(url))
Expand Down Expand Up @@ -438,13 +438,17 @@ public String doDelete(String url, RequestParameter... postVariables)
}

public String uploadFile(String url, File file) throws IOException, JsonStatusException {
return uploadFile(url, file, file.getName());
}

public String uploadFile(String url, File file, String filename) throws IOException, JsonStatusException {

url = HypersocketUtils.encodeURIPath(url);

url = buildUrl(url);

RequestBody requestBody = new MultipartBody.Builder().setType(MultipartBody.FORM)
.addFormDataPart("file", file.getName(),
.addFormDataPart("file", filename,
RequestBody.create(file, MediaType.parse("application/octet-stream")))
.build();

Expand Down

0 comments on commit 3cbb411

Please sign in to comment.