我开发了一个Android应用程序,如何将文件上传到sharepoint与android? 文件很大。
答案 0 :(得分:1)
您可以通过网络服务完成。如果您在SharePoint 2013上 - 它为此提供了REST服务。只需提出PUT请求即可。如果是SharePoint 2010 - 您需要对SOAP服务的请求。 有关于在SharePoint 2013中上载的文章:Uploading Files Using the REST API 大约有2010版:Upload documents to SharePoint 2010
答案 1 :(得分:1)
public int uploadFile(String directoryPath, String file_path){
if (siteHost.isEmpty() || !isLogin) return ERROR_LOGIN;
String webserviceUrl = "http://site:port/_vti_bin/listdata.svc/SharedDocuments";
String slug = "http://site:port/Shared%20Documents/filename";
File file = new File(file_path);
if (file == null) return ERROR_FILE;
String file_name = file.getName();
ContentBody filebody = new FileBody(file);
HttpPost post = new HttpPost(webserviceUrl);
post.getParams().setBooleanParameter(CoreProtocolPNames.USE_EXPECT_CONTINUE, false);
post.setHeader("Content-Type","multipart/form-data");
post.setHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
post.setHeader("Accept-Encoding", "gzip, deflate");
post.setHeader("Accept-Language", "zh-cn,zh;q=0.8,en-us;q=0.5,en;q=0.3");
post.setHeader("User-Agent", "Mozilla/5.0 (Android; Mobile; rv:28.0) Gecko/28.0 Firefox/28.0");
post.addHeader("Slug",slug);
MultipartEntity multipartContent = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
multipartContent.addPart(file_name, filebody);
post.setEntity(multipartContent); ;
try {
HttpResponse response = defaultHttpClient.execute(post);
int resCode = response.getStatusLine().getStatusCode();
if (resCode != 201) return ERROR_UPLOAD;
} catch (IOException e) {
e.printStackTrace();
return ERROR_UPLOAD;
}
return ERROR_SUCCESS;
}