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.

1 Answer 1


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:

    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");


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.