Here's a sample arcpy geoprocessing toolbox with a tool that returns a file.
Some notes
-
Your parameter file must have a
direction
ofOutput
and aparameterType
ofDerived
-
The file type for geoprocessing parameter is "DEFile", for some reason
GPDataFile
results in no file being accessible to end user. Once published it appears asGPDatafile
-
Result must be set via arcpy.setParameterAsText whereas setting "value" of a saved parameter does nothing.
-
In order to be accessible you file must be wrote/saved to "arcpy.env.scratchFolder". Arcpy rewrite this path once published to an accessible URL.
-
If you wish to backup your file outside of "arcpy.env.scratchFolder" you have to register the save location, from ArcGIS Pro: add any folder you need via: Share→Manage→Data stores, here add a new
folder
withPublish folder path
set to the path you want to expose. Keep in mind that any hard coded path will be consolidated (to a sandbox path) on publish by ArcGIS.
Some useful links
I also published this code to community.esri.com