1

For SharePoint, when we want our third party Java app to access the files from within document libraries, we currently grab files using HTTP get request.

But if the file is too large, it won't work.

Is there a way to get a file's size by URI with a single rest call?

1
  • 2
    something like /_api/web/lists/getByTitle('Document Library')/Files?$select=Size ? Commented Nov 9, 2016 at 18:54

4 Answers 4

2

You can use below rest api to get file size without downloading file...

<yourdomain>/_api/web/getFileByServerRelativeUrl('/path/file.ext')/Properties

You will get one node with below name which will return file size....

<d:vti_x005f_filesize m:type="Edm.Int32">1003</d:vti_x005f_filesize>
2

The Files endpoint might be of use:

/_api/web/lists/getByTitle('Document Library')/Files?$select=Size

When I ran it against an arbitrary library, it indicated a lot of 0 file sizes, so ymmv.

You can call an endpoint like Siddharth shows. In the results of the call I've indicated, there is an endpoint to call for the specific file. It will look something like:

https://tenant.sharepoint.com/sites/sitename/_api/Web/Lists(guid'd32192c7-03b3-4a77-8156-481fb5fe4032')/files('1V-kjHLvM0-ZrgVSDNe-OtX54xS-Fz1Prx5Ucgn8azrOUaDIpwNcTY5qwu9ivln5')

So you could call the initial Files endpoint I referenced, then depending on what you are doing, call the individual file endpoint for further information

2
  • Does that work for a single file? Please advise. Commented Nov 9, 2016 at 23:03
  • added some more information Commented Nov 10, 2016 at 14:26
2

This example should work:

${site url}/_api/lists/getbytitle('${Title Name}')/items?$select=File/Length&$expand=File

I can get data from Document library.

Note: I'm using the SharePoint online site, I'm not sure if it would work on the old version.

0

You can get the size of the file from the HTTP headers too.

https://stackoverflow.com/questions/263013/java-urlconnection-how-can-i-find-out-the-size-of-a-web-file

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.