We can use the below REST API code to read the specific file from SharePoint:
var requestUri = _spPageContextInfo.webAbsoluteUrl +
"/_api/web/lists/getByTitle('My Documents')/items?$select=EncodedAbsUrl&$filter=Id eq 6";
var requestHeaders = {
"accept": "application/json;odata=verbose"
}
$.ajax({
url: requestUri,
type: 'GET',
dataType: 'json',
headers: requestHeaders,
success: function (data)
{
$.each(data.d.results, function(i,result) {
var path = result.EncodedAbsUrl;
var fileTemplate= result.Template;
});
},
error: function ajaxError(response) {
alert(response.status + ' ' + response.statusText);
}
});
Note:
- var path = result.EncodedAbsUrl; - This gives the absolute URL of the file
- now type result.Template which will give the template name - may be the exact template attribute name will be different, then in the debug mode (F12) after result.
type "Templ" - then we will get the exact attribute name.
Reference:
Get documents By ID from document library using Rest API