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
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
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:
https://api.orthanc-server.com/#tag/System/paths/~1tools~1create-archive/post
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:
https://book.orthanc-server.com/users/support.html#discussing-a-minimal-working-example
Kind Regards,
Sébastien-
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.
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.
The JS code for the Stone Viewer is available at:
https://hg.orthanc-server.com/orthanc-stone/file/tip/Applications/StoneWebViewer/WebApplication/app.js
Search for: “DownloadStudy: function(studyInstanceUid, event)”
That might give you some ideas, but it uses axios for the requests.
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”.
FYI, this GET route has been implemented in Orthanc 1.12.2.
example:
http://localhost:8042/tools/create-archive?resources=ca29faea-b6a0e17f-067743a1-8b778011-a48b2a17,1e2c125c-411b8e86-3f4fe68e-a7584dd3-c6da78f0&transcode=1.2.840.10008.1.2.4.70
HTH,
Alain.