SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How can I fetch the attachments (the URL, to be precise) of a list item with SPServices (the jQuery library)?

share|improve this question

How to retrieve attachment files using SPServices

function getAttachmentFiles(listName,listItemId,complete) 
        operation: "GetAttachmentCollection",
        async: false,
        listName: listName,
        ID: listItemId,
        completefunc: function(xData, Status) {
            var attachmentFileUrls = [];    
            $(xData.responseXML).find("Attachment").each(function() {
               var url = $(this).text();



function printAttachments(urls){
    for(var i =0; i< urls.length; i++){
share|improve this answer
Just a heads up to sleepy people like me, don't forget to change the listName and ID to your list and the item ID which has the image on the func. Else you'll get a _vti_bin/Lists.asmx 500 (Internal Server Error) error in the console) – Mint Jul 14 '15 at 23:55

This should get you where you need to go:

ExecuteOrDelayUntilScriptLoaded(getWebProperties, "SP.js");            
var attachmentFiles;

function getWebProperties() {
    var itemId=2;
    var ctx = new SP.ClientContext.get_current();
    var web = ctx.get_web();
    var attachmentFolder=web.getFolderByServerRelativeUrl('Lists/City/Attachments/'+itemId);
    attachmentFiles= attachmentFolder.get_files();

function onSuccess(sender, args) {                                      
    var i=0;
    for(var file in attachmentFiles) {                              

function onFailed(sender, args) {
share|improve this answer

I just wanted to amend an alternate formation of the onSuccess function that worked better for me:

function onSuccess(sender, args) {                                      
    var i = 0;
    while (attachmentFiles.itemAt(i)) {
        var file = attachmentFiles.itemAt(i).get_serverRelativeUrl();
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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