Closed cpesch closed 3 years ago
Hello
PLGSharepointClient wrapper = new PLGSharepointClientOnline(user, passwd, domain, spSiteUrl);
try {
Resource result = wrapper.downloadFile("/sites/YOURSITE/LIBRARY/FILENAME.EXTENSION);
System.out.println(result);
InputStream is = new BufferedInputStream(result.getInputStream());
OutputStream os = new BufferedOutputStream(new FileOutputStream("./test.EXTENSION"));
IOUtils.copy(is, os);
is.close();
os.close();
Assert.assertTrue(result != null );
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
Assert.assertTrue(false);
}
Can you try adapting this to a OnPremises instance adapting the download URL? This is extracted from a test i used to test the methods and to test changes. The file url must contain the the full uri of the file, including the /site/SITENAME where the library is located.
With online instance this is working
Here are my findings:
I've tried to add a header like described https://sharepoint.stackexchange.com/questions/273774/how-to-get-content-of-file-in-sharepoint-using-sharepoint-rest-api but this doesn't change the Content-Type header that Sharepoint returns. You can find the change here: https://github.com/cpesch/PLGSharepointRestAPI-java/commit/34c2a2ad2414533817eff641afa16114ef941a75
I made a workaround and adjusted the Content-Type header if it has not subtype. This works but it's not nice: https://github.com/cpesch/PLGSharepointRestAPI-java/commit/e20ff6600ebbc745e1b78009ecd733f0dca16edb
Dear @kikovalle,
I'm trying to download the bytes of a CSV file from a Sharepoint 2013 and I'm using PLGSharepointOnPremisesClient#downloadFile
I'm using the serverRelativeUrl which works when accessing it from the browser.
When using the call above, I receive this exception:
I've tried to submit "Accept: application/octet-stream" or omit sending the Accept header like here https://docs.microsoft.com/en-us/sharepoint/dev/sp-add-ins/working-with-folders-and-files-with-rest but this doesn't help.
Do you have experiences with that?