I want to get the Attachment URL with via REST or Javascript. Is there an easy way?
The reason I need this, is because I want to build a marketplace in my company.
- User creates new list item
- User can upload a picture
- User saves form
I want to display the list item in a "nice" way with picture, name, title... I got everything, but not the attachment URL.
Here my code:
<script type="text/javascript">
$(document).ready(function() {
// Rest URL
var requestUri = "/_api/lists/getbytitle('Marketplace')/items";
var picUrl;
$.ajax({
url: requestUri,
type: "GET",
headers: { "ACCEPT": "application/json;odata=verbose" },
success: function (data) {
$.each(data.d.results, function (i, item){
var title = item.Title;
var searchOffer = item.SearchOffer;
var category = item.Category;
var description = item.Description;
var price = item.Price;
var id = item.ID;
var authorId = item.AuthorId;
document.getElementById("market" + i).innerHTML = "<img class='img-responsive' src='**???**' alt=''><h2>" + title + "</h2><p>" + description + "</p>";
})
},
error: function () {
alert("Error getting the Marketplace Items");
}
});
});
</script>
In the innerHTML I need the Attachment URL as source.
An other option I already tried was to use this requestUri:
items?$select=Attachments,AttachmentFiles,Title&$expand=AttachmentFiles
But then I cant get the ServerRelativeUrl into a variable... Any ideas there?
I tried it also with a second REST Request /items(id)/AttachmentFiles, but it can't be that hard to get this, right?
Any help?