根据Skydrive API(http://msdn.microsoft.com/en-us/library/live/hh826531.aspx#uploading_files),我在发布请求的主体中将字节内容传递给byte []。 文件创建发生在skydrive服务器上,但是当我在skydrive中打开它时,它说“该文件存在损坏或损坏”。使用java将文件上传到skydrive
体POST请求的
--A300x 内容处置:形状数据; NAME = “文件”;文件名= “菜单的icon.png” 内容类型:应用/八位字节流
[[email protected]
--A300x--
来自服务器的响应。用于将图像转换成字节
<html>
<head>
<script type="text/javascript">
window.location = "http://localtesting.com/mywebapp-1.0-SNAPSHOT#state=000000004C0FA618&result=%7b%22id%22%3a%22file.918bb0fbaf82f760.918BB0FBAF82F760!139%22%2c%22name%22%3a%22menu-icon.png%22%2c%22source%22%3a%22https%3a%2f%2f1m61va.tuk.livefilestore.com%2fy2mhncDTiOhUVFZxp08gi3yAFhp7OQ2-UYuQhnC_Obpoo4q5tG6onLuJz2mLJkJh6lUW5l8Cq2KBxvrLRrZ0bk6V7xmfso47cJWAw1fKE8bFJw%2fmenu-icon.png%3fdownload%26psid%3d1%22%7d";
</script>
</head>
</html>
代码[]
字节[]图像= FileUtils.readFileToByteArray(physicalfile);
任何线索?
编辑: 以下是代码片段我用
我带有些地区的属性文件。
env.properties
part1=--A300x\u000d\u000aContent-Disposition: form-data; name=\"file\"; filename=\"
part2=\"\u000d\u000aContent-Type: application/octet-stream\u000d\u000a\u000d\u000a
part3=\u000d\u000a--A300x--
java file
String part1=bundle.getString("part1");
String part2= fileName+bundle.getString("part2");
String part3=bundle.getString("part3");
byte[] imageByteArray=FileUtils.readFileToByteArray(physicalfile);
PostMethod postMethod= new PostMethod("https://apis.live.net/v5.0/"+folderPath+"/files?state="+getSkydriveClientId()+"&redirect_uri="+baseURL+"&access_token="+getAcessToken());
postMethod.setRequestHeader("Content-Type","multipart/form-data; boundary=A300x");
postMethod.setRequestBody(part1+part2+imageByteArray+part3);
HttpClient httpClient=new HttpClient();
httpClient.executeMethod(postMethod);