【发布时间】:2022-02-10 21:00:18
【问题描述】:
我有一个场景,在我的代码中创建了一个文件和一个累积事件。我需要将二进制文件附加到事件中,但是 API 都没有为我提供功能,请指导如何继续?
更新:
在查看文档 https://cumulocity.com/api/10.11.0/#tag/Attachments 时,binaryElement 具有以下结构
我已通过以下方式修改了我的 JAVA 代码:
String pathEvent = platform.getUrl().get()+"/event/events/{{eventId}}/binaries";
String pathEventAttachment = pathEvent.replace("{{eventId}}", event.getId().getValue());
HttpHeaders headers = RequestAuthenticationEncoder.encode(getCredentials());
headers.setContentType(MediaType.MULTIPART_FORM_DATA);
MultiValueMap<String, Object> map = new LinkedMultiValueMap<>();
map.add("file",new ByteArrayResource(FileUtils.readFileToByteArray(file)));//anychanges here fails the code
map.add("filename", file.getName().getBytes());
HttpEntity<MultiValueMap<String, Object>> request = new HttpEntity<>(map,headers);
restTemplate.postForObject(pathEventAttachment, request, String.class);
log.info("Binary file added to the event {}", event.getId().getValue());
请告诉我一些关于为什么名称没有改变的见解?
【问题讨论】:
标签: java cumulocity