v1/files/move - response missing or??

Started by ubacher, September 06, 2017, 02:32:25 PM

Previous topic - Next topic

ubacher

IMWS.post('v1/files/move' ...
does not seem to return a response.

And: it would be good if the response could indicate if the file ( existed) and was replaced or not.

Mario

#1
The response is HTTP status code 200 OK if the operation is successful, else a HTTP 500 with additional info. Try to move a non-existing file.

The result depends on what you specify for the replace parameter.
You can easily tell if the target file already existed. Or use the filesystem/files/info endpoint to determine if a file exists in advance.
-- Mario
IMatch Developer
Forum Administrator
http://www.photools.com  -  Contact & Support - Follow me on 𝕏 - Like photools.com on Facebook

ubacher

I use the following code:
IMWS.post('v1/files/move', {
                        idlist: IMatch.idlist.fileWindowSelection,
                        target: folderName,
                        replace: 'makeunique'
                    }).then(function (responseM) {
                        if (responseM.result == 'ok') {
                          }
                        else {
                            alert('move to pano ' + JSON.stringify(responseM, null, 2));
                        }
                    },
                        function (error) {
                            alert('file move error ' + error.status + ' ===' + error.statusText);
                        }
                        )

I get the alert showing: move to pano {}
The debugger shows responseM to be an object, responseM.result undefined.
The move takes place however!

thrinn

My understanding is: There is no need for an explicit "result == 'ok'" because the Promise returned by the endpoint only resolves (-> "then" part) if everything worked ok. If there is an error the Promise is rejected, meaning only the reject part (your function (error)) is executed. In this case, the error parameter contains additional information about what kind of error happened.
Thorsten
Win 10 / 64, IMatch 2018, IMA

Mario

Correct.
The then function is only executed by JS when the server returned 200OK. Else it will call the error function. So:

IMWS.post('v1/files/move', {}).then(function()) {
  // Yay! Worked.
}
,function(error) {
// Oops. Check error for error codes and details.
});
-- Mario
IMatch Developer
Forum Administrator
http://www.photools.com  -  Contact & Support - Follow me on 𝕏 - Like photools.com on Facebook