I need to check the uploading file is already exist in the document library or not by using RESt-api or jsom. Please suggest some idea.
3
You can make use of the getfilebyserverrelativeurl
to determine whether file exists or not.
Try and modify the below code (using REST). Ensure that you are passing the server relative url of the file:
jQuery.ajax({
url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/getfilebyserverrelativeurl('/sites/testsite/Documents/test.txt')",
type: "GET",
headers: {
"accept": "application/json;odata=verbose"
},
success: function(data){
console.log("file exists");
},
error: function(error){
if(error.status == 404){
console.log("file doesnt exist");
}
}
});