Uploading large SD files and publishing as feature services

3261
0
11-21-2015 06:33 AM
PeterMoeller-Christensen
New Contributor

Hi there,

I really have a tough time getting python based feature service creation to work. I finally got an answer from Maarten van Hulzen in Holland, who showed me how to first upload the SD file and then publish like this:

   #Upload:

    import requests

    ....

    filesUp = {"file": open(sdFile, 'rb')}

    r = requests.post(url, files=filesUp,verify=False);

   resultJson = r.json()

   itemID = resultJson['id']

    #Publish

    LogMessage("Start publish job")

    publishURL = portal +'/sharing/rest/content/users/{}/publish'.format(UserName)

    url = publishURL + "?f=json&token=" + token

    pubParams ='{"name":"'+serviceName.encode('utf-8').strip() + '","title":"' +serviceTitle.encode('utf-8').strip() + '"}'

    publishParams = {'itemID': itemID, 'filetype': 'serviceDefinition','overwrite':True,  'publishParameters':pubParams}

    r = requests.post(url,publishParams,verify=False

However, for large files, this doesn't work. I get a MemoryError. Using

    from requests_toolbelt import (MultipartEncoder)

    ...

    payload = MultipartEncoder({"file": open(sdFile, 'rb'),"name":os.path.basename(sdFile)})

    r = requests.post(url,data=payload,verify=False,headers={"Content-Type": payload.content_type})

I can now upload files, but publish fails with:

message=Error getting Item Info from DataStore

messageCode=PUB_0031

Using requests and MultipartEncoder is nice and simple, but there must be something missing on the uploaded Service Definition, giving problems to publishing.

Does anybody have an idea how to solve this? Thanks in advance.

0 Kudos
0 Replies