Web Messenger Java SDK for file uploads

We are using web-messaging-sdk-8.0.0.jar and we are trying to upload images to a Web Messaging deployment in a messaging session from the Customer to the Agent.

When we are making attachment through webMessagingClient(WebMessagingClient) "attach" method, it comes to "presignedUrlResponse" and file parts are coming null. How can we upload a file through Java SDK ? Or can we ?
We used this documentation to try and learn how to do it https://github.com/MyPureCloud/web-messaging-sdk-java.

presignedUrlResponse: class PresignedUrlResponse {
    attachmentId: a9379649-ea2e-475b-9587-a1a126842f5e
    headers: {x-amz-tagging=organizationId=REMOVED_INTENTIONALLY&originPlatform=PureCloud&role=darth&owner=Dev-CloudAppsDarth@genesys.com}
    url: https://fileupload.usw2.pure.cloud/webmessaging/uploads/161e39b0-d368-4148-bb2e-c5f46aee2e2f/60b30110-c764-43b8-9c30-d3a070f38353.test.PNG?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=ASIA3EQYLGB7RMQ4R3LM%2F20230324%2Fus-west-2%2Fs3%2Faws4_request&X-Amz-Date=20230324T084628Z&X-Amz-Expires=900&X-Amz-SignedHeaders=host%3Bx-amz-tagging&X-Amz-Security-Token=IQoJb3JpZ2luX2VjEAkaCXVzLXdlc3QtMiJIMEYCIQDyOROGpLqtoaLndoAV4NBYrhk4Vt%2F5VTsC71DfkGbpLQIhAPrgQs1LgpGNbDhdlNDhAMzK9IKoK36BSFrFxACSb7siKpYDCNH%2F%2F%2F%2F%2F%2F%2F%2F%2F%2FwEQABoMNzY1NjI4OTg1NDcxIgztTsP7jQvC8Txwe%2FAq6gIZEkBg8yLh%2BdHFAHl0bZolYPbYAKpWblB%2Fs0J8XU6KsGIBh1PxjsuwQoETC9i7zuCWefh8gxtQhXqv3f7JFt3C2rEonBY%2BRAFIHL2RDRr2aUDy7MEAQPCpCZmDK9q0ATkNHIgr9Yke%2B5eN48IzLMwuCqhEJ1AGUKUzpnFw4VsF6czlbWYIn7ofbsWEq1Lr0%2FMhjatLtZxuefKvxp2huybuyaMMQ4tV%2FwHRPinZ3v94ec0vXX4X9o4gtxjWzZsv8gU7gLbxoS%2By3WmuHSN6dGcadgHQ%2BnpHxSXiALc5NaCiM6viV2qjFVjvYPPEs8iNuXKL6NhYsseORz8HQXpYzwp6Bo6NSzUBfk8zlUhcYIARRwRSnJ8ln8AnsIvYlN7pqvliPPGhgBLuboDMADV8ud%2FEkbLIY1gg2ix%2FviRK10wbmtdXhNr05h9f7nz4YlzsR%2BLhsi6OGTAAmjMlafumDwWo7xMNHwTuhD1SAzDlu%2FWgBjqcAVJJFVGLWJFA2W9CVQ%2BuVtq7cNG0bVFmQFRcidZYDCldPMSjeBEIBZPx9NDkql3Oj%2FbRzrEzs1bWfJUmv0Ltt75YR76eSwuUNT0CO0cehuMiKbplDiXlCHBfFZBauxE%2FVQmVV%2BPmtw4Zxh8HRUYkq5Nyh%2Fx%2BzCcMJEWxqsiIUxNGjrcMpNBIWkI5jxtiQ1WW767uFMG%2FeFIiNpdhvg%3D%3D&X-Amz-Signature=feb7bda23384edac0c575fd6425b5b788e5765f166f663df5b423cddd31584a9
    fileName: null
    fileSize: null
    fileType: null
}
1 Like

Andrei,

The logs show that your file was not successfully uploaded.
I see that we send back an error 4010 / "Attachment a9379649-ea2e-475b-9587-a1a126842f5e was not successfully uploaded"
Please note that attachment() only gives you the url where you can upload your file.
After you generated the upload url, did you actually upload your file?
Did you receive the corresponding UploadSuccessEvent?

hi Julien, we are not receiving UploadSuccessEvent. Which method should we use after attachment()? Inside presignedUrl fileName etc are coming null.

Thank you!
Andrei

You need to issue a rest request to upload your file to the upload url, something like:

CloseableHttpResponse closeableHttpResponse;
try (CloseableHttpClient client = HttpClientBuilder.create().build()) {
  HttpPut put = new HttpPut(uploadUrl);
  presignedUrl.getHeaders().forEach(put::setHeader);
  put.setEntity(new FileEntity(imageFile(fileName), ContentType.create(mimeType)));
  closeableHttpResponse = client.execute(put);
} catch (IOException ioException) {
  //...
}
closeableHttpResponse.getStatusLine().getStatusCode();// should be 200

The presignedUrl should contain fileName, fileSize and fileType originally provided to the WebMessagingClient.attachment() method.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.