我正在尝试使用Jersey 2.0为Dropbox实现REST客户端。
以下代码正常,我的文件已成功上传到Dropbox。
String targetUrl = "https://api-content.dropbox.com/1/files_put?access_token=" + token.access_token + "&root=dropbox&path=Public/" + file.getName();
WebTarget target = client.target(targetUrl);
final FileDataBodyPart filePart = new FileDataBodyPart("file", file);
final MultiPart multipart = new FormDataMultiPart().bodyPart(filePart);
Response response = target.request()
.put(Entity.entity(multipart, multipart.getMediaType()));
但是,上传的文件中包含不必要的MIME边界。
原始档案:
response : {
"hash": "3ebf46d672258e1e190b70cc1f0dd5ce",
"revision": 87707813,
…
"size": "0 bytes"}
上传文件:
--Boundary_1_393888375_1373874680685
Content-Type: text/plain
Content-Disposition: form-data; filename="Dropbox.txt"; modification-date="Fri, 12 Jul 2013 04:23:29 GMT"; size=1328; name="file"
response : {
"hash": "3ebf46d672258e1e190b70cc1f0dd5ce",
"revision": 87707813,
…
"size": "0 bytes"}
--Boundary_1_393888375_1373874680685--
是否可以从上传的文件中删除MIME边界?
答案 0 :(得分:0)
您使用Content-Type: multipart/form-data
上传。
您可以看到边界,因为text/plain
内有multipart/form-data
。
回答您的问题,是的,如果您使用text/plain
更改要上传的代码,则边界将会继续。