<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Geoprocessing service to return a file in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/geoprocessing-service-to-return-a-file/m-p/1277808#M67402</link>
    <description>&lt;P&gt;For further reader, here's a sample geoprocessing toolbox with a tool that returns a file.&lt;/P&gt;&lt;H4&gt;Some notes&lt;/H4&gt;&lt;P&gt;- Your parameter file must have a "direction" of "Output" and a "parameterType" of "Derived"&lt;/P&gt;&lt;P&gt;- 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 as "GPDatafile"&lt;/P&gt;&lt;P&gt;- Result must be set via&amp;nbsp;&lt;A href="https://pro.arcgis.com/fr/pro-app/latest/arcpy/functions/setparameterastext.htm" target="_blank" rel="noopener"&gt;arcpy.setParameterAsText&lt;/A&gt;&amp;nbsp;whereas setting "value" of a saved parameter does nothing.&lt;/P&gt;&lt;P&gt;- 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.&lt;/P&gt;&lt;P&gt;- If you wish to backup your file outside of&amp;nbsp;"arcpy.env.scratchFolder" you have to register the save location, from ArcGIS Pro:&amp;nbsp;&lt;SPAN&gt;add any folder you need via: Share→Manage→Data stores, here add a new &lt;/SPAN&gt;&lt;SPAN&gt;`folder`&lt;/SPAN&gt;&lt;SPAN&gt; with &lt;/SPAN&gt;&lt;SPAN&gt;`Publish folder path`&lt;/SPAN&gt;&lt;SPAN&gt; 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.&lt;/SPAN&gt;&lt;/P&gt;&lt;H4&gt;&amp;nbsp;Some useful links&lt;/H4&gt;&lt;P&gt;-&amp;nbsp;&lt;A href="https://pro.arcgis.com/en/pro-app/latest/help/analysis/geoprocessing/share-analysis/authoring-web-tools-with-python-scripts.htm" target="_blank" rel="noopener"&gt;&lt;SPAN&gt;Authoring web tools with Python scripts (to understand path consolidation)&lt;/SPAN&gt;&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;- &lt;A href="https://pro.arcgis.com/en/pro-app/latest/help/analysis/geoprocessing/share-analysis/publishing-web-tools-in-arcgis-pro.htm" target="_blank" rel="noopener"&gt;Publish web tool&lt;/A&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;H4&gt;The code&lt;/H4&gt;&lt;LI-CODE lang="python"&gt;# -*- coding: utf-8 -*-

import arcpy
from os.path import join

class Toolbox(object):
    def __init__(self):
        """Sample file toolbox"""
        self.label = "Sample file toolbox"
        self.alias = "File toolbox"

        # List of tool classes associated with this toolbox
        self.tools = [GetFileTool]

class GetFileTool(object):

    def __init__(self):
        """Define the tool (tool name is the name of the class)."""
        self.label = "Get file tool"
        self.description = "A tool to get a file"
        self.canRunInBackground = False

    def getParameterInfo(self):
        """Define parameter definitions"""
        return [arcpy.Parameter(displayName="Output_File",
                                name='Output_File',
                                datatype=['DEFile'],
                                parameterType='Derived',
                                direction='Output')]

    def isLicensed(self):
        """Set whether tool is licensed to execute."""
        return True

    def updateParameters(self, parameters):
        """Modify the values and properties of parameters before internal
        validation is performed.  This method is called whenever a parameter
        has been changed."""
        return

    def updateMessages(self, parameters):
        """Modify the messages created by internal validation for each tool
        parameter.  This method is called after internal validation."""
        return
    
    def exitWithError(self,msg):
        """
            exit geoprocessing with a given error msg
            under the hood it raise an exception, msg is logged as error
        """
        raise ValueError(msg)

    def execute(self, parameters, messages):
        """The source code of the tool."""
        p = join(arcpy.env.scratchFolder, "test.txt")
        with open(p, 'w') as f:
            f.write('hello')
        #set result with SetParameterAsText, setting result via 'value' parameter of objects inside parameters does nothing
        arcpy.SetParameterAsText(0,p)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 12 Apr 2023 14:25:50 GMT</pubDate>
    <dc:creator>Marc_Alx</dc:creator>
    <dc:date>2023-04-12T14:25:50Z</dc:date>
    <item>
      <title>Geoprocessing service to return a file</title>
      <link>https://community.esri.com/t5/python-questions/geoprocessing-service-to-return-a-file/m-p/522062#M40927</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;How can I get a geoprocessing service to return a file?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I published a GP&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;SPAN class="keyword token"&gt;if&lt;/SPAN&gt; __name__ &lt;SPAN class="operator token"&gt;==&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'__main__'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;

    file &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; open&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;env&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;scratchWorkspace&lt;SPAN class="operator token"&gt;+&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"/"&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;+&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"test.txt"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"w"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
    file&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;write&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"why"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
    file&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;close&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
    arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;SetParameter&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;0&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; file&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;name&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;‍‍‍‍‍‍‍‍‍‍‍‍&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;':&lt;/P&gt;&lt;P&gt;however i kept receiving the&amp;nbsp;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt; "value": "d:\\arcgisserver\\directories\\arcgisjobs\\script_gpserver\\j94a7e5b06f3342deb0ebcb65467f63fe\\scratch/test.txt"&lt;/PRE&gt;&lt;P&gt;I can see the file in the scratch folder but i need to return the file some how.&lt;/P&gt;&lt;P&gt;&lt;IMG __jive_id="500859" class="image-1 jive-image" src="https://community.esri.com/legacyfs/online/500859_pastedImage_1.png" /&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I did try to access the file via different permutation of&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://example.com/arcgis/rest/services/Script/GPServer/Script/jobs/j94a7e5b06f3342deb0ebcb65467f63fe/scratch/text.txt" target="_blank"&gt;https://example.com/arcgis/rest/services/Script/GPServer/Script/jobs/j94a7e5b06f3342deb0ebcb65467f63fe/scratch/text.txt&lt;/A&gt; to no avail&lt;/P&gt;&lt;P&gt;Can someone kindly assist.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 22:46:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/geoprocessing-service-to-return-a-file/m-p/522062#M40927</guid>
      <dc:creator>VictorTey</dc:creator>
      <dc:date>2021-12-11T22:46:23Z</dc:date>
    </item>
    <item>
      <title>Re: Geoprocessing service to return a file</title>
      <link>https://community.esri.com/t5/python-questions/geoprocessing-service-to-return-a-file/m-p/522063#M40928</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi &lt;A href="https://community.esri.com/migrated-users/327767"&gt;Victor Tey&lt;/A&gt;,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Why do you put a forward slash between the path and the file?&lt;/P&gt;&lt;P&gt;What happens if you replace this &lt;CODE&gt;&lt;SPAN class=""&gt;"/"&lt;/SPAN&gt; &lt;/CODE&gt;with &lt;CODE&gt;&lt;SPAN class=""&gt;"\\"&lt;/SPAN&gt;&lt;/CODE&gt;?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Does this solve your issue?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;BR,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Egge-Jan&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 21 Jul 2020 09:30:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/geoprocessing-service-to-return-a-file/m-p/522063#M40928</guid>
      <dc:creator>Egge-Jan_Pollé</dc:creator>
      <dc:date>2020-07-21T09:30:45Z</dc:date>
    </item>
    <item>
      <title>Re: Geoprocessing service to return a file</title>
      <link>https://community.esri.com/t5/python-questions/geoprocessing-service-to-return-a-file/m-p/522064#M40929</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;PRE style="color: #000000; background-color: #e5eff7; border: 0px;"&gt;j94a7e5b06f3342deb0ebcb65467f63fe&lt;/PRE&gt;&lt;P&gt;This number differs from the one in the your image... is that supposed to happen?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 21 Jul 2020 09:38:56 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/geoprocessing-service-to-return-a-file/m-p/522064#M40929</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2020-07-21T09:38:56Z</dc:date>
    </item>
    <item>
      <title>Re: Geoprocessing service to return a file</title>
      <link>https://community.esri.com/t5/python-questions/geoprocessing-service-to-return-a-file/m-p/522065#M40930</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I had rewritten the code several times&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;txtFile = os.path.join(arcpy.env.scratchFolder, "myTxt.txt")&lt;BR /&gt; f = open(txtFile, 'w')&lt;BR /&gt; f.writelines("huh")&lt;BR /&gt; f.close&lt;BR /&gt; arcpy.SetParameterAsText(0, txtFile)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;One of them is as shown above, still the same &lt;IMG src="https://community.esri.com/legacyfs/online/emoticons/sad.png" /&gt;.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have arcgis enterprise installed locally, would that have made a difference?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 21 Jul 2020 10:29:21 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/geoprocessing-service-to-return-a-file/m-p/522065#M40930</guid>
      <dc:creator>VictorTey</dc:creator>
      <dc:date>2020-07-21T10:29:21Z</dc:date>
    </item>
    <item>
      <title>Re: Geoprocessing service to return a file</title>
      <link>https://community.esri.com/t5/python-questions/geoprocessing-service-to-return-a-file/m-p/522066#M40931</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;My apologies, I had so many tabs opened and I must have copy and paste from the wrong tab &lt;IMG src="https://community.esri.com/legacyfs/online/emoticons/sad.png" /&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;IMG __jive_id="500860" class="image-1 jive-image" src="https://community.esri.com/legacyfs/online/500860_pastedImage_1.png" /&gt;&lt;/P&gt;&lt;P&gt;&lt;IMG __jive_id="500873" class="image-2 jive-image" src="https://community.esri.com/legacyfs/online/500873_pastedImage_2.png" /&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;txtFile &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; os&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;path&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;join&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;env&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;scratchFolder&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"myTxt.txt"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
    f &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; open&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;txtFile&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'w'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
    f&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;writelines&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"huh"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
    f&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;close
    arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;SetParameterAsText&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;0&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; txtFile&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;‍‍‍‍‍&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 22:46:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/geoprocessing-service-to-return-a-file/m-p/522066#M40931</guid>
      <dc:creator>VictorTey</dc:creator>
      <dc:date>2021-12-11T22:46:25Z</dc:date>
    </item>
    <item>
      <title>Re: Geoprocessing service to return a file</title>
      <link>https://community.esri.com/t5/python-questions/geoprocessing-service-to-return-a-file/m-p/522067#M40932</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;STRONG&gt;Superseded by my comment above but still useful!&amp;nbsp;&lt;/STRONG&gt; To answer your original question, to return your output file parameter (in Pro) wrap &lt;EM&gt;the web tool&lt;/EM&gt; in a model and add the Copy geoprocessing tool to copy it into your project.&amp;nbsp; The file has to be a supported type.&amp;nbsp; Here is an example where the web tool is a Spatial ETL tool which I featured in my recent UC technical workshop on Data Interoperability extension.&amp;nbsp; The experience of a web tool output going to a rather obscure profile directory is under review by geoprocessing team.&amp;nbsp; Note:&amp;nbsp; The intermediate scratchfile will be deleted when you exit Pro, this is also under review.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;IMG __jive_id="500888" class="image-1 jive-image" src="https://community.esri.com/legacyfs/online/500888_pastedImage_1.png" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 21 Jul 2020 13:28:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/geoprocessing-service-to-return-a-file/m-p/522067#M40932</guid>
      <dc:creator>BruceHarold</dc:creator>
      <dc:date>2020-07-21T13:28:23Z</dc:date>
    </item>
    <item>
      <title>Re: Geoprocessing service to return a file</title>
      <link>https://community.esri.com/t5/python-questions/geoprocessing-service-to-return-a-file/m-p/522068#M40933</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you all for your help. It turns out I have been really silly.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I kept attempting to access the file via&amp;nbsp; "arcgis/rest/services/&lt;/P&gt;&lt;P&gt;arcgis/rest/services/Script5/GPServer/Script/jobs/j24670b8fb4944b60993fa840472bc2f8/results/URL&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;where else the output of the directory is actually on&amp;nbsp;&lt;SPAN&gt;arcgis/rest/directories/arcgisjobs&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;arcgis/rest/directories/arcgisjobs/script5_gpserver/j05515f60833c4e15a8d461f40acb1484&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 21 Jul 2020 14:05:33 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/geoprocessing-service-to-return-a-file/m-p/522068#M40933</guid>
      <dc:creator>VictorTey</dc:creator>
      <dc:date>2020-07-21T14:05:33Z</dc:date>
    </item>
    <item>
      <title>Re: Geoprocessing service to return a file</title>
      <link>https://community.esri.com/t5/python-questions/geoprocessing-service-to-return-a-file/m-p/522069#M40934</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Victor, the team here notice your output data type is GPString, please change it to GPFile. it should then work.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 21 Jul 2020 18:47:11 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/geoprocessing-service-to-return-a-file/m-p/522069#M40934</guid>
      <dc:creator>BruceHarold</dc:creator>
      <dc:date>2020-07-21T18:47:11Z</dc:date>
    </item>
    <item>
      <title>Re: Geoprocessing service to return a file</title>
      <link>https://community.esri.com/t5/python-questions/geoprocessing-service-to-return-a-file/m-p/522070#M40935</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Spot on, thank you so much &lt;IMG src="https://community.esri.com/legacyfs/online/emoticons/happy.png" /&gt;, this is my first attempt working with publishing GP and trying to piece together how everything works together&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 22 Jul 2020 01:27:00 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/geoprocessing-service-to-return-a-file/m-p/522070#M40935</guid>
      <dc:creator>VictorTey</dc:creator>
      <dc:date>2020-07-22T01:27:00Z</dc:date>
    </item>
    <item>
      <title>Re: Geoprocessing service to return a file</title>
      <link>https://community.esri.com/t5/python-questions/geoprocessing-service-to-return-a-file/m-p/1277808#M67402</link>
      <description>&lt;P&gt;For further reader, here's a sample geoprocessing toolbox with a tool that returns a file.&lt;/P&gt;&lt;H4&gt;Some notes&lt;/H4&gt;&lt;P&gt;- Your parameter file must have a "direction" of "Output" and a "parameterType" of "Derived"&lt;/P&gt;&lt;P&gt;- 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 as "GPDatafile"&lt;/P&gt;&lt;P&gt;- Result must be set via&amp;nbsp;&lt;A href="https://pro.arcgis.com/fr/pro-app/latest/arcpy/functions/setparameterastext.htm" target="_blank" rel="noopener"&gt;arcpy.setParameterAsText&lt;/A&gt;&amp;nbsp;whereas setting "value" of a saved parameter does nothing.&lt;/P&gt;&lt;P&gt;- 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.&lt;/P&gt;&lt;P&gt;- If you wish to backup your file outside of&amp;nbsp;"arcpy.env.scratchFolder" you have to register the save location, from ArcGIS Pro:&amp;nbsp;&lt;SPAN&gt;add any folder you need via: Share→Manage→Data stores, here add a new &lt;/SPAN&gt;&lt;SPAN&gt;`folder`&lt;/SPAN&gt;&lt;SPAN&gt; with &lt;/SPAN&gt;&lt;SPAN&gt;`Publish folder path`&lt;/SPAN&gt;&lt;SPAN&gt; 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.&lt;/SPAN&gt;&lt;/P&gt;&lt;H4&gt;&amp;nbsp;Some useful links&lt;/H4&gt;&lt;P&gt;-&amp;nbsp;&lt;A href="https://pro.arcgis.com/en/pro-app/latest/help/analysis/geoprocessing/share-analysis/authoring-web-tools-with-python-scripts.htm" target="_blank" rel="noopener"&gt;&lt;SPAN&gt;Authoring web tools with Python scripts (to understand path consolidation)&lt;/SPAN&gt;&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;- &lt;A href="https://pro.arcgis.com/en/pro-app/latest/help/analysis/geoprocessing/share-analysis/publishing-web-tools-in-arcgis-pro.htm" target="_blank" rel="noopener"&gt;Publish web tool&lt;/A&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;H4&gt;The code&lt;/H4&gt;&lt;LI-CODE lang="python"&gt;# -*- coding: utf-8 -*-

import arcpy
from os.path import join

class Toolbox(object):
    def __init__(self):
        """Sample file toolbox"""
        self.label = "Sample file toolbox"
        self.alias = "File toolbox"

        # List of tool classes associated with this toolbox
        self.tools = [GetFileTool]

class GetFileTool(object):

    def __init__(self):
        """Define the tool (tool name is the name of the class)."""
        self.label = "Get file tool"
        self.description = "A tool to get a file"
        self.canRunInBackground = False

    def getParameterInfo(self):
        """Define parameter definitions"""
        return [arcpy.Parameter(displayName="Output_File",
                                name='Output_File',
                                datatype=['DEFile'],
                                parameterType='Derived',
                                direction='Output')]

    def isLicensed(self):
        """Set whether tool is licensed to execute."""
        return True

    def updateParameters(self, parameters):
        """Modify the values and properties of parameters before internal
        validation is performed.  This method is called whenever a parameter
        has been changed."""
        return

    def updateMessages(self, parameters):
        """Modify the messages created by internal validation for each tool
        parameter.  This method is called after internal validation."""
        return
    
    def exitWithError(self,msg):
        """
            exit geoprocessing with a given error msg
            under the hood it raise an exception, msg is logged as error
        """
        raise ValueError(msg)

    def execute(self, parameters, messages):
        """The source code of the tool."""
        p = join(arcpy.env.scratchFolder, "test.txt")
        with open(p, 'w') as f:
            f.write('hello')
        #set result with SetParameterAsText, setting result via 'value' parameter of objects inside parameters does nothing
        arcpy.SetParameterAsText(0,p)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 12 Apr 2023 14:25:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/geoprocessing-service-to-return-a-file/m-p/1277808#M67402</guid>
      <dc:creator>Marc_Alx</dc:creator>
      <dc:date>2023-04-12T14:25:50Z</dc:date>
    </item>
    <item>
      <title>Re: Geoprocessing service to return a file</title>
      <link>https://community.esri.com/t5/python-questions/geoprocessing-service-to-return-a-file/m-p/1340912#M69022</link>
      <description>&lt;P&gt;This is super helpful. I couldn't for the life of me find documentation or other support indicating how to write a layer package or other file to an output parameter and how the server could send that back to the client. Even my ESRI support wasn't aware of this option and was suggesting my server save my output to a network folder. Thanks so much!&lt;/P&gt;</description>
      <pubDate>Tue, 24 Oct 2023 14:34:04 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/geoprocessing-service-to-return-a-file/m-p/1340912#M69022</guid>
      <dc:creator>LukasHoupt</dc:creator>
      <dc:date>2023-10-24T14:34:04Z</dc:date>
    </item>
    <item>
      <title>Re: Geoprocessing service to return a file</title>
      <link>https://community.esri.com/t5/python-questions/geoprocessing-service-to-return-a-file/m-p/1567821#M73324</link>
      <description>&lt;P&gt;I know this is old&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/1173"&gt;@BruceHarold&lt;/a&gt;&amp;nbsp; but on server 11.3 Scratch Workspace is not giving back the job dir from arcgisjobs dir.&amp;nbsp; Instead it is giving and writing to AppData under the user name.&amp;nbsp; This dir is not part of the cleanup schedule and it growing over time.&lt;/P&gt;&lt;P&gt;arcpy.AddMessage("Scratch Workspace " + arcpy.env.scratchWorkspace)&lt;/P&gt;&lt;P&gt;Scratch Workspace C:\Users\serveruser~1\AppData\Local\Temp\aim\speedtest_gpserver\j9b2d66b7a00d4a8696d2fe7973da3ba4\scratch&lt;/P&gt;&lt;P&gt;The post in here shows it should be my arcgisjobs dir right?&lt;/P&gt;&lt;P&gt;I am even seeing it create the jobs dir with a scratch folder in the arcgisjobs folder and even a scratch GDB but it does not use it.&amp;nbsp; I can find no way in script to find this jobs dir either.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="DougBrowning_0-1734018741952.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/121565i4B31220082466BC4/image-size/medium?v=v2&amp;amp;px=400" role="button" title="DougBrowning_0-1734018741952.png" alt="DougBrowning_0-1734018741952.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Why is it not using arcgisjobs as configured both in the GP tool and in the server settings?&lt;/P&gt;&lt;P&gt;thanks&lt;/P&gt;</description>
      <pubDate>Thu, 12 Dec 2024 15:59:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/geoprocessing-service-to-return-a-file/m-p/1567821#M73324</guid>
      <dc:creator>DougBrowning</dc:creator>
      <dc:date>2024-12-12T15:59:45Z</dc:date>
    </item>
    <item>
      <title>Re: Geoprocessing service to return a file</title>
      <link>https://community.esri.com/t5/python-questions/geoprocessing-service-to-return-a-file/m-p/1567883#M73325</link>
      <description>&lt;P&gt;H Doug, can you please open a&amp;nbsp; support call.&amp;nbsp; I know that sounds like a canned response but in this case we'll have to rope in geoprocessing team and they need something to track for their work.&amp;nbsp; Thanks for reaching out.&lt;/P&gt;</description>
      <pubDate>Thu, 12 Dec 2024 17:02:35 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/geoprocessing-service-to-return-a-file/m-p/1567883#M73325</guid>
      <dc:creator>BruceHarold</dc:creator>
      <dc:date>2024-12-12T17:02:35Z</dc:date>
    </item>
  </channel>
</rss>

