[FAQ] How to Track Download Success using startDrag API

Applies to: io.Connect Desktop 9.7.1 and later.

Question

When using io.windows.my().startDrag() to enable native file drag-and-drop from a web app, how can I tell whether the file download succeeded or failed in order to display an appropriate message when it completes?

Answer

The promise resolves with an IOConnectWindow, not with a download result object. It carries no information about the downloaded file itself. Whether the download succeeded is signalled by whether the promise resolves or rejects, not by what it resolves with.

From io.Connect Desktop 9.7.1 onwards, the promise reflects the HTTP response status returned by the server:

  • Rejected - the server returns a status code outside the 2** range.
  • Resolved - the server returns a status code in the 2** range.

Note: startDrag() checks the HTTP status code, not the content of the response. If anything in the request chain answers with a 2**, the promise resolves, even if the bytes that came back are not the file you asked for. That can happen with URLs behind authentication. In one support case, the first request was redirected to an authentication panel, which returned 200. That is a valid HTTP success, so there was no error for the platform to raise. Once the user had authenticated, subsequent requests to the same URL returned the expected 500, so the logic had to be adapted.

For the StartDragOptions object and a usage example, see the Native File Drag & Drop section of the documentation.

Before 9.7.1, an HTTP error response such as 500 could still result in the promise resolving, so awaiting the promise could not reliably distinguish a successful response from a failed one. If you are on an earlier version, upgrading is the resolution - the fix is in the platform and requires no changes on the application side.

Related resources