4

我们正在尝试使用 3.0.5.RELEASE 中的 org.springframework.web.client.RestTemplate 作为 REST 调用的一部分进行文件上传,我们看到了一些文件,几乎所有的 Open Office 和 OOXML 格式,显示为我们的服务器端默认应用程序/八位字节流。

我们可以在上传之前使用 Tika 检测 mime-type,但看不到如何通过 RestTemplate 将其添加到请求的一部分中。下面是我们用来执行上传的一些 Groovy 代码:

MultiValueMap<String, Object> form = new LinkedMultiValueMap<String, Object>()
form.add("title", document.title)
form.add("description", document.description)
form.add("content", new FileSystemResource(file))
return restTemplate.postForObject(getFullURL(REST_API_URI), form, Document.class)
4

0 回答 0