0

Does SharePoint have metadata for file size and checksum via REST?

Retrieving Metadata

I can retrieve and item's information using:

_api/web/GetFileByServerRelativeUrl('/path/file.ext')/ListItemAllFields

I can see many metadata information, including created and modified dates. That said, I haven't seen any metadata item that shows the file's size. Is the information available?


End Goal

What I would really like is to retrieve all the metadata for all files in a specific folder, including the file size and checksum.

My current method involves downloading the file and obtaining the file size locally, which is more resource intensive than I'd like -- I'd especially like to avoid downloading large files.

Likewise, is there a checksum that could be used to compare local files to those stored in SharePoint?

2 Answers 2

2

Make a GET request using this It will show response in JSON format.

You can use the below rest Api to make a request.

/_api/web/getfilebyserverrelativeurl('/Library Name/DocumentName.doc')/Length?@target='http://YourSiteUrl/'

And you should be able to see the response in JSON format like this with the Length of the file: enter image description here

OR Using Ajax call and you can get the Length and convert it to Human readable format:

 $.ajax({
    url: "/_api/web/getfilebyserverrelativeurl('/LibraryName/DocumentName.doc')/Length?@target=http://YourSiteUrl/", //THE ENDPOINT
    method: "GET",
    headers: {
        "Accept": "application/json; odata=verbose"
    },
    success: function(data) {

        console.log(getFileSize(data.d.Length));

        function getFileSize(size) {
            var i = Math.floor( Math.log(size) / Math.log(1024) );
            return ( size / Math.pow(1024, i) ).toFixed(2) * 1 + ' ' + ['B', 'kB', 'MB', 'GB', 'TB'][i];
        };

    },

    error: function(data) {
        failure(data); // Do something with the error
    }

  });

You can see the file size in kb in the Console log:

enter image description here

1

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>

Not sure about checksum but I see streamhash as one of property...

<d:vti_x005f_streamhash>0x0294A7C818EE18894876DF25B5326D60910A24A820</d:vti_x005f_streamhash>
5
  • Are these properties documented anywhere? That's a lazy question, since I haven't searched yet (but plan to). Also, do do you know of any way to do this for multiple files in a folder? I want to reduce HTTP requests if I can. -- Otherwise, this is perfect and will most likely be my accepted answer once I give it a try!
    – BotNet
    Nov 9, 2016 at 17:49
  • Unfortunately, it didn't work -- I was able to getFolderByServerRelativeUrl('/path')/Properties, but not for the file
    – BotNet
    Nov 9, 2016 at 17:53
  • But according to the MSDN, there's a "length" property, which is the file size: msdn.microsoft.com/en-us/library/office/…
    – BotNet
    Nov 9, 2016 at 18:01
  • It should work for file also, I have given a try and then posted above answer xml nodes which in answer represent actual file size, what are you getting when trying ? You can direct put above in any browser and you should get xml response... Nov 10, 2016 at 4:00
  • Just what I mentioned the getFileBy.../Properties doesn't display the vti...filesize, but does include a Length; whereas the getFolderBy.../Properties does have the filesize. I don't think that's a limitation of my implementation, since the help docs seem to confirm what I'm seeing.
    – BotNet
    Nov 15, 2016 at 18:39

Your Answer

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

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