create-archive not downloading studies

88 views
Skip to first unread message

farooq.a...@gmail.com

unread,
Mar 29, 2023, 7:27:19 AM3/29/23
to Orthanc Users
Hi all,

I am trying to download multiple studies using Orthanc's API "/create-archive" endpoint with a fetch request in a React app.
The problem is that I am not getting any zip file downloaded when I execute that fetch request in Chrome.

By inspecting the network tab, I can see that the fetch request executed successfully with a 200 OK status.

I have also used the "/archive" endpoint for downloading single study, and that was very easy to use, and it also works to download a zip file containing that specific study.

This is how my fetch request looks like

const requestBody = {
    Resources: data,
  };

  if (data.length > 0) {
    fetch(PACS_URL['origin'] + '/' + currentPacs + '/tools/create-archive', {
      method: 'POST',
      headers: {
        'Access-Control-Allow-Origin': '*',
        'Access-Control-Allow-Headers': '*',
        'Content-Type': 'application/json',
        Accept: 'application/zip',
      },
      body: JSON.stringify(requestBody),
    });
}

Is there something that I am missing here? Please guide me.
Thanks in Advance.

Regards 
Farooq Butt

Stephen Douglas Scotti

unread,
Mar 29, 2023, 12:20:54 PM3/29/23
to Orthanc Users
That is more like a javascript question if everything else is working OK.  I have some legacy that does something similar.  It looks like you don't have a callback, the 'thens'.

You could probably adapt that ?


function downloadstudy_orthanc(type, clicked)  {

$("#spinner").css("display", "block");

fetch('/OrthancDev/downloadStudyUUID', {

    body: JSON.stringify({command: type, "uuid": clicked.data( "uuid")}),
    method: 'POST',
    headers: {
        'Content-Type': 'application/json; charset=utf-8',
        'csrf-token' : $("meta[name='csrf-token']").attr("content")

    },
})
.then(response => response.blob())
.then(response => {

    $("#spinner").css("display", "none");
    const blob = new Blob([response], {type: 'application/zip'});
    const downloadUrl = URL.createObjectURL(blob);
    const a = document.createElement("a");
    a.href = downloadUrl;
    a.download = clicked.data("name") + ".zip";
    document.body.appendChild(a);
    a.click();
    showMessage("Download Study", "Check you Downloads Folder");
})

}

/sds

Sébastien Jodogne

unread,
Mar 29, 2023, 3:29:58 PM3/29/23
to Orthanc Users
Hello,

I would suggest you to separate concerns, by trying to use the "/tools/create-archive" from the command line using curl. You can find the full documentation of this URI at the following location:

If you are not able to reproduce your issue using curl, this would indicate an issue in the React application. If you are able to reproduce your issue using curl, please share a full minimal working example so that we can independently reproduce and correct the issue:

Kind Regards,
Sébastien-


On Wednesday, March 29, 2023 at 1:27:19 PM UTC+2 farooq.a...@gmail.com wrote:

farooq.a...@gmail.com

unread,
Mar 30, 2023, 2:16:22 AM3/30/23
to Orthanc Users
Hi  Sébastien,

I have used this "/tools/create-archive" from the command line using curl; it is working fine there, and I also got the zip file. There is no problem with this endpoint when using it with the curl command-line interface.

If I follow the "Stephen Douglas Scotti" answer method, then I am getting the zip file, but the problem is, I have to use the response.blob() thing to get my zip file of studies. and when I use this response.blob() takes some time to download a zip file; it does not show me download progress on the "Chrome Download Toolbar" like we see when we download something from Google Chrome; it just takes some time and then directly shows the full downloaded zip file in the "Chrome Download Toolbar".

and that is not what I want; I want to see the download progress like we see when we download other things from Chrome.

and also there's a question that I wanna ask here, why we need to use blob() to get zip file because according to your orthanc API documentation 
Synchronous: "If true, create the archive in synchronous mode, which means that the HTTP answer will directly contain the ZIP file. This is the default, easy behavior."
According to the above, after making a post request to /create-archive", it should automatically download the zip file without doing any blob() thing with the fetch request.

Stephen Douglas Scotti

unread,
Mar 30, 2023, 3:10:32 AM3/30/23
to Orthanc Users
That is a legacy thing from some development code for another purpose.  You could also look at the Stone Viewer Code and consult StackOverFlow or some other place like that for JS questions like that.


Search for:  "DownloadStudy: function(studyInstanceUid, event)"

That might give you some ideas, but it uses axios for the requests.

farooq.a...@gmail.com

unread,
Mar 30, 2023, 5:40:30 AM3/30/23
to Orthanc Users
The "DownloadStudy: function(studyInstanceUid, event)" is for downloading a single study, I have also implemented this in my React application, and it works fine; it shows me download progress whenever I download a single study using a fetch request with "/archive" endpoint.

But I want that same thing with the "/create-archive" endpoint as well. because "create-archive" doesn't return a zip file if I don't use response.blob() and when I use response.blob(), it takes some time and then directly shows the zip file without showing any download progress at the "Chrome Download Toolbar".

Alain Mazy

unread,
Mar 31, 2023, 10:34:54 AM3/31/23
to farooq.a...@gmail.com, Orthanc Users
Hi Farooq,

I'm afraid you won't be able to achieve what you are looking for.  A browser will display the "download in progress" only when the user clicks on a <a> link which means that on the backend side, this must be implemented by a GET request.  Since the /create-archive is a POST, that won't work.

Possible workaround: implement a new GET route in a python plugin and make that python code make the POST to /create-archive.

Note that I've added this to our TODO: this might be useful to implement download from multiple selection in OE2.  However, I can't tell when this will be implemented:

Also implement a GET variant of /tools/create-archive + sibling routes in which resources & transcode options are provided as get arguments.

Best regards,

Alain.




--
You received this message because you are subscribed to the Google Groups "Orthanc Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to orthanc-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/orthanc-users/4c24a95f-3a7f-4bff-b658-a6e224085a98n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages