Select to view content in your preferred language

How to set filename for export web map task (print)

554
2
12-02-2023 06:39 AM
BradBarnell
New Contributor III

I am using the "print" task.  Not to be confused with the print widget.

 import * as print from "@ArcGIS/core/rest/print.js";

The documentation says this:

  • If the application and the print service are on the same origin, the name of the downloadable file can be customized with the fileName or title properties. If not, the name of the downloadable file will be generated by the ArcGIS Enterprise that hosts the print service.

But there is not a property called fileName or title on print.  On the print widget, I saw TemplateOptions which had this property, but not on print.

How do I set the download filename???

2 Replies
JoelBennett
MVP Regular Contributor

The print service doesn't actually accept a custom file name for the file it generates.  Instead, the Print widget works by using the link element's download property to tell the browser to save the output file with a different name.

You can reproduce this just using the print module with something like the following:

print.execute(url, printParameters).then(function(dataFile) {
	fetch(dataFile.url).then(function(response) {
		response.blob().then(function(blob) {
			var a = document.createElement("a");
			a.style.display = "none";
			a.href = window.URL.createObjectURL(blob);
			a.target = "_blank";
			a.download = "MyFile" + dataFile.url.substring(dataFile.url.lastIndexOf("."));
			document.body.appendChild(a);
			a.click();
			a.remove();
			a = null;
		});
	});
});

 

Noah-Sager
Esri Regular Contributor

@JoelBennett has the correct answer. I think the print known limitations doc should be updated to be more accurate for this scenario.

0 Kudos