1 Reply Latest reply on Oct 1, 2014 1:21 AM by johnrellis

    How to cancel LrHttp.post calls




      I'm working on an export/publish service.  Before the uploading happens, there is some interaction with the remote application.  In general, whenever I launch an call I'd like to provide some feedback to the user that it's doing something and give them the option of canceling.  Currently, I have a LrTasks.startAsyncTask which leads into LrFunctionContext.callWithContext and then a LrDialogs.showModalProgressDialog.  After the dialog box comes up, the function drops into an LrHttp.post call.  I'm trying to figure out how if there is a way to connect the isCanceled property of the progressScope to the ability to cancel the LrHttp.post call.  (Currently, the only thing I can think of is to write a byte feeding and have it suddenly stop feeding bits. Any thoughts?


      -Scott Selberg

        • 1. Re: How to cancel LrHttp.post calls
          johnrellis Most Valuable Participant

          The postBody parameter of LrHTTP.post() can be a function that returns the data to be sent in chunks.  You could have that function check a "cancelled" flag and return nil if the flag is set.  The behavior is not well specified and it's not clear what will happen if the function returns nil before it has returned the number of bytes specified by the totalBytes parameter -- does the HTTP POST get aborted?  If it doesn't get aborted, you could have the server side check to ensure that the number of bytes received in the body matches the Content-Length header (assuming that LrHTTP adds such a header).