<?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 Uploading large SD files and publishing as feature services in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/uploading-large-sd-files-and-publishing-as-feature/m-p/69212#M5644</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi there,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;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:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; #Upload:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; import requests&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ....&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; filesUp = {"file": open(sdFile, 'rb')}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; r = requests.post(url, files=filesUp,verify=False);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; resultJson = r.json()&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; itemID = resultJson['id']&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; #Publish&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; LogMessage("Start publish job")&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; publishURL = portal +'/sharing/rest/content/users/{}/publish'.format(UserName)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; url = publishURL + "?f=json&amp;amp;token=" + token &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; pubParams ='{"name":"'+serviceName.encode('utf-8').strip() + '","title":"' +serviceTitle.encode('utf-8').strip() + '"}'&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; publishParams = {'itemID': itemID, 'filetype': 'serviceDefinition','overwrite':True,&amp;nbsp; 'publishParameters':pubParams}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; r = requests.post(url,publishParams,verify=False&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;However, for large files, this doesn't work. I get a MemoryError. Using &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; from requests_toolbelt import (MultipartEncoder)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; payload = MultipartEncoder({"file": open(sdFile, 'rb'),"name":os.path.basename(sdFile)})&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; r = requests.post(url,data=payload,verify=False,headers={"Content-Type": payload.content_type})&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I can now upload files, but publish fails with:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;message=Error getting Item Info from DataStore&lt;/P&gt;&lt;P&gt;messageCode=PUB_0031&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Using requests and MultipartEncoder is nice and simple, but there must be something missing on the uploaded Service Definition, giving problems to publishing.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Does anybody have an idea how to solve this? Thanks in advance.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 21 Nov 2015 14:33:59 GMT</pubDate>
    <dc:creator>PeterMoeller-Christensen</dc:creator>
    <dc:date>2015-11-21T14:33:59Z</dc:date>
    <item>
      <title>Uploading large SD files and publishing as feature services</title>
      <link>https://community.esri.com/t5/python-questions/uploading-large-sd-files-and-publishing-as-feature/m-p/69212#M5644</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi there,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;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:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; #Upload:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; import requests&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ....&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; filesUp = {"file": open(sdFile, 'rb')}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; r = requests.post(url, files=filesUp,verify=False);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; resultJson = r.json()&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; itemID = resultJson['id']&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; #Publish&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; LogMessage("Start publish job")&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; publishURL = portal +'/sharing/rest/content/users/{}/publish'.format(UserName)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; url = publishURL + "?f=json&amp;amp;token=" + token &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; pubParams ='{"name":"'+serviceName.encode('utf-8').strip() + '","title":"' +serviceTitle.encode('utf-8').strip() + '"}'&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; publishParams = {'itemID': itemID, 'filetype': 'serviceDefinition','overwrite':True,&amp;nbsp; 'publishParameters':pubParams}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; r = requests.post(url,publishParams,verify=False&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;However, for large files, this doesn't work. I get a MemoryError. Using &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; from requests_toolbelt import (MultipartEncoder)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; payload = MultipartEncoder({"file": open(sdFile, 'rb'),"name":os.path.basename(sdFile)})&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; r = requests.post(url,data=payload,verify=False,headers={"Content-Type": payload.content_type})&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I can now upload files, but publish fails with:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;message=Error getting Item Info from DataStore&lt;/P&gt;&lt;P&gt;messageCode=PUB_0031&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Using requests and MultipartEncoder is nice and simple, but there must be something missing on the uploaded Service Definition, giving problems to publishing.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Does anybody have an idea how to solve this? Thanks in advance.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 21 Nov 2015 14:33:59 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/uploading-large-sd-files-and-publishing-as-feature/m-p/69212#M5644</guid>
      <dc:creator>PeterMoeller-Christensen</dc:creator>
      <dc:date>2015-11-21T14:33:59Z</dc:date>
    </item>
  </channel>
</rss>

