0

I have an app that allows users to upload TIFF files so that an ImageServer is created in ArcGIS 10.5 Server. However, I don't want to keep the images over a day.

Is there a way of automatically removing an image service using ArcPy?

The code below does not work as it seems to be designed for Desktop:

arcpy.Delete_management(url)

The same question is asked in Esri community here and here with no answer.

  • Of course it's possible. You do need to use the correct operation (REST API). You have your choice of frameworks and languages; though Python is an option, it's not an ArcPy function. – Vince May 20 '19 at 11:42
  • That is good to know. Could you post the python code that will work as answer? – wondim May 20 '19 at 11:58
  • My code to do this is ~150 LOC, doesn't handle HTTPS well, and is not on my phone. Oh, and was cobbled from samples from before the ArcGIS API for Python was released. You really ought to be researching that before rolling your own. – Vince May 20 '19 at 12:20
  • You mean your code cost 150k dollars? – wondim May 20 '19 at 12:29
  • Lines Of Code. It cost my client way more to assemble than $150. – Vince May 20 '19 at 12:34
0

I found a solution using a code to publish service from the Esri website. The code below uses python to delete a service by name. The requests module works well with no errors while I faced problems when using httplib, urlopen, and urllib2 to send the request.

import requests

def delete_service(service_name):
    username = 'name'
    password = 'pass'
    serverPort = 443
    serverName = 'mydomain'
    # getToken() code is available in the link above. 
    token = getToken(username, password, serverName)
    if token == "":
        print "Could not generate a token with the username and password provided."
        return
    deleteServiceURL = "https://mydomain.com/arcgis/admin/" \
                       "services/myfolder/{}/ImageServer/delete".format(
        service_name)

    params = urllib.urlencode({'token': token, 'f': 'json'})
    headers = {"Content-type": "application/x-www-form-urlencoded",
               "Accept": "text/plain"}
    response = requests.post(deleteServiceURL, params=params, headers=headers)
    # Connect to URL and post parameters, only post allowed for service creation
    if (response.status_code != 200):
        # httpConn.close()
        print "Error while creating the service."
        return
    else:
        data = response.json()
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.