1

I am currently facing the following issue with a Java program.

I am trying to upload a file I downloaded from an external server (file type can be different for every execution) to a IBM RTC (or Jazz) server through REST call.

The REST endpoint I am sending the first request (i.e.: the file upload to the central repository) is as the following:

https://jazz.host.com:1234/ccm/service/com.ibm.team.workitem.service.internal.rest.IAttachmentRestService/?projectId=<TEAM_AREA_ID>&multiple=true&category=<CATEGORY_ID>

And this step works, uploading the file to the central repo. What it is not working is the fact that when the attachment name contains some kind of characters (i.e.: £, ù, °, ...) those are changed into the character ?.

I am using Apache HttpClient with a CloseableHttpClient, preparing the HttpEntity to be sent as follows:

    java.io.File currentAttachmentFile = utils.getFileFromPath(attachmentPath);
    MultipartEntityBuilder builder = MultipartEntityBuilder.create();
    builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
    builder.addBinaryBody("upfile", currentAttachmentFile, ContentType.MULTIPART_FORM_DATA, currentAttachmentFile.getName());
    return builder.build();

But even sepcifying the withCharset(StandardCharsets.UTF8) to ContentType.MULTIPART_FORM_DATA does not do the trick, the file name stile contains the ? character (while I expect it to be something like: 'file_name 1!==£$%&^+ù°#@'.png').

I took a look around for other suggestions but neither those found here and here are working for the file name. Moreover, specifying the Content-Type to the POST call I am sending causes a failure with the message 'Invalid POST request message' returned by RTC, so this can't be an option.

Through PostMan, the upload with the same file to the same endpoint works so I suppose there is something I am missing when creating the entity to send to RTC.

Does anyone know how to solve this?

Best regards,

Alberto

Olaf Kock
  • 46,930
  • 8
  • 59
  • 90
AlSteve
  • 65
  • 1
  • 9
  • Have you tried explicitly converting the source filename to UTF-8 encoding prior to uploading? Something like: `byte[] bytes = currentAttachmentFile.getName().getBytes(StandardCharsets.UTF_8);` and then: `utf8Filename = new String(bytes, StandardCharsets.UTF_8);`. Then use the `utf8Filename` in your `builder.addBinaryBody` call. – j_b Aug 27 '21 at 12:29
  • Hi @j_b , just gave it a try and still i see the file name (once uploaded) with the '?' in place of the above listed chars. – AlSteve Aug 30 '21 at 08:56

0 Answers0