0

I have a SharePoint list with attachments in its items. Now I want to show the attachment size in the item View Form and Edit form. But I cannot find a JavaScript API to get the attachment size.

I tried the OData service but it only returns the file name. Apparently I cannot download these files... _api/web/lists/getbytitle('My%20Documents')/items(1)/AttachmentFiles

So in short, How can I get item attachment size in JavaScript? (I am using SharePoint 2013)

2 Answers 2

1

You can grab the serverrelativeurl of the file from your request. Pass it to another request like so: _api/web/getfilebyserverrelativeurl('/Lists/TestList/Attachments/1/blabla.xlsx'). This will give you the file length in Bytes.

3

Use below REST API example

url: "<app web url>/_api/SP.AppContextSite(@target)/web
    /getfilebyserverrelativeurl('/Shared Documents/filename.docx')/Length

For more info: MSDN

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.