How to upload document file to sharepoint online with REST POST method using java in android platform?
-
miércoles, 01 de agosto de 2012 7:26
Hi everyone, I'm developing android mobile application managing document files in sharpoin online.
I' looking for the way to upload documnet file to sharepoint online libraries using httpclient and Post method in java.
but I cant't find the detail information about the usage. (For example, URL and the way to set header and parameters)
If you have experienced about this function and ideas, please share them with us. Thanks for reading.
Some code is like below, and now response is 404 Error (Not found).
String url = "https://muhan16.sharepoint.com/_vti_bin/ListData.svc/LIB_TEST_1";
DefaultHttpClient httpclient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(url);
httpPost.setHeader("Cookie", loginInfo.cookieString);
httpPost.setHeader("ENCTYPE", "multipart/form-data");
httpPost.setHeader("Slug", url +"/" + "WORD_TEST_1_a.docx");
HttpParams params = httpclient.getParams();
params.setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
HttpConnectionParams.setConnectionTimeout(params, 0);
HttpConnectionParams.setSoTimeout(params, 0);
String str=is.toString();
byte[] data = str.getBytes();
InputStreamBody isb = new InputStreamBody(new ByteArrayInputStream(data), "WORD_TEST_1_a.docx");
MultipartEntity multipartContent = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE, null, Charset.forName("UTF-8"));
File file = new File("/sdcard/" + "WORD_TEST_1_a.docx");
FileBody cbFile = new FileBody(file);
// Log.d(LOG_TAG, "fileSize : " + String.valueOf(file.length()));
// multipartContent.addPart("fileSize", new StringBody(String.valueOf(file.length())));
multipartContent.addPart("file", cbFile);
httpPost.setEntity(multipartContent);
try {
HttpResponse response = httpclient.execute(httpPost);
BufferedReader reader = new BufferedReader(new InputStreamReader(
response.getEntity().getContent(), "UTF-8"));
Log.d(LOG_TAG, "Status code:" +response.getStatusLine().getStatusCode());
String sResponse;
StringBuilder s = new StringBuilder();while ((sResponse = reader.readLine()) != null) {
s = s.append(sResponse);
}
Log.d(LOG_TAG, "Response:" + s);
} catch (Exception e) {
e.printStackTrace();
} finally{
httpclient.getConnectionManager().shutdown();
}
Todas las respuestas
-
martes, 07 de agosto de 2012 18:47Moderador
Hi,
From the look of the URL that you posted, you are using SharePoint 2010 with Office365. This forum is for customers that are using SharePoint 2007 with BPOS. You will want to look off the SharePoint Online for Office 365 Developer Guide regarding your question. After you look through the developer guide, if you still have questions, you will want to post your question in the Office 365 SharePoint forums.
Thanks,
Tim Muth
Microsoft Online Services Tehcnical Support

