I have a custom list on sharepointonline, and I have attached a file (myfile.txt) to an item (itemid=5). How can I download this attachment?

I am able download the file with this button:

<a type="button" href={'https://mydomain/Lists/Announcements/Attachments/'+this.state.ItemId+'/myfile.txt'} className="btn btn-info" download>Download Attachment</a>

I am able to get ItemId with the REST API, but there is no name of attachment files. The only question here is: How do I get the attachment file names like other columns 'Title', 'Created'? I expect 'AttachmentName', but none ofc.

  • 1
    Can you add some code as to how you formed this url like REST API ? Commented Feb 3, 2017 at 9:51
  • Sorry missing that part but your answer already what i am looking for. thanks! Commented Feb 3, 2017 at 9:59
  • What is "ofc" (in this context)? Original female character? Of course? Something else? Commented Feb 3, 2017 at 17:33

2 Answers 2


Your REST query should be as below:


In the JSON results, you can get the file name as below:

for (var i = 0; i < data.d.results.length; i++) {    
    var item = data.d.results[i];
    var attachmentUrl = item.AttachmentFiles.results[0];
    var fileName = attachmentUrl.FileName;
  • Can you check the post please, AttachmentFiles contains no information about files in response, what i am doing wrong here ? Commented Feb 3, 2017 at 10:16
  • 1
    did you append $expand=AttachmentFiles in the query ? Commented Feb 3, 2017 at 10:18
  • Yeah its ok now :) Commented Feb 3, 2017 at 10:22

You need to either use /AttachmentFiles like this


or expand it like this


The / method only works on single items, where expand works with your OData query

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.