<?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: Add PDF document (item) to organizational portal in ArcGIS Pro SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/add-pdf-document-item-to-organizational-portal/m-p/1029804#M6242</link>
    <description>&lt;P&gt;I still haven't been able to get past the&amp;nbsp;&lt;SPAN&gt;502 Bad Gateway error but wanted to bump this issue back to the top and add my current code. I did find some mistakes in my previous submission. Hopefully someone has been able to get this function to work in the last year or so?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;var myPortal = ArcGISPortalManager.Current.GetActivePortal();&lt;BR /&gt;string strToken = myPortal.GetToken();&lt;BR /&gt;var owner = myPortal.GetSignOnUsername();&lt;BR /&gt;var url = $"&lt;A href="https://www.arcgis.com/sharing/rest/portals/self?f=json&amp;amp;token=" target="_blank"&gt;https://www.arcgis.com/sharing/rest/portals/self?f=json&amp;amp;token=&lt;/A&gt;" + strToken;&lt;BR /&gt;var response = new EsriHttpClient().Get(url);&lt;BR /&gt;var json = await response.Content.ReadAsStringAsync();&lt;BR /&gt;dynamic portalSelf = JObject.Parse(json);&lt;/P&gt;&lt;P&gt;var uploadUrl = "https://" + Convert.ToString(portalSelf.urlKey) +&lt;BR /&gt;".maps.arcgis.com/sharing/rest/content/users/" + owner + "/addItem";//convert filestream to byte array&lt;BR /&gt;byte[] fileBytes;&lt;BR /&gt;using (var fileStream = File.OpenRead("C:\\Docs\\animas_AOI_prms\\maps_publish\\title_page.pdf"))&lt;BR /&gt;{&lt;BR /&gt;var binaryReader = new BinaryReader(fileStream);&lt;BR /&gt;fileBytes = binaryReader.ReadBytes((int)fileStream.Length);&lt;BR /&gt;}&lt;BR /&gt;var fileBinaryContent = new ByteArrayContent(fileBytes);&lt;/P&gt;&lt;P&gt;string strTitle = "Testing 1 2 3";&lt;/P&gt;&lt;P&gt;using (var formData = new MultipartFormDataContent())&lt;BR /&gt;{&lt;BR /&gt;// Add the HttpContent objects to the form dataformData.Add(new StringContent("json"), "f");&lt;BR /&gt;formData.Add(new StringContent(strToken), "token");&lt;BR /&gt;formData.Add(new StringContent("true"), "async");&lt;BR /&gt;formData.Add(new StringContent("PDF"), "type");&lt;BR /&gt;formData.Add(new StringContent(strTitle), "title");&lt;BR /&gt;formData.Add(new StringContent("eBagis"), "tags");&lt;BR /&gt;formData.Add(new StringContent("upload from BAGIS"), "description");&lt;BR /&gt;var multipartContent = new MultipartFormDataContent&lt;BR /&gt;{&lt;BR /&gt;{ fileBinaryContent, "file" }&lt;BR /&gt;};&lt;BR /&gt;formData.Add(multipartContent);&lt;/P&gt;&lt;P&gt;// Invoke the request to the server&lt;BR /&gt;// equivalent to pressing the submit button on&lt;BR /&gt;// a form with attributes (action="{url}" method="post")&lt;BR /&gt;response = await new EsriHttpClient().PostAsync(uploadUrl, formData);&lt;BR /&gt;json = await response.Content.ReadAsStringAsync();&lt;BR /&gt;}&lt;/P&gt;</description>
    <pubDate>Tue, 23 Feb 2021 22:21:45 GMT</pubDate>
    <dc:creator>LesleyBross1</dc:creator>
    <dc:date>2021-02-23T22:21:45Z</dc:date>
    <item>
      <title>Add PDF document (item) to organizational portal</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/add-pdf-document-item-to-organizational-portal/m-p/813438#M2442</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'm trying to&amp;nbsp;upload a PDF document to our organization's portal from an ArcGIS Pro add-in. I have been unable to find this functionality in the current API so am trying to use the REST API. When I run it, Pro churns away so I think it is uploading but I always&amp;nbsp;receive a&amp;nbsp;502 Bad Gateway response.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here is my current code:&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P&gt;var url = $"https://www.arcgis.com/sharing/rest/portals/self?f=json&amp;amp;token=" + strToken;&lt;BR /&gt; var response = new EsriHttpClient().Get(url);&lt;BR /&gt; var json = await response.Content.ReadAsStringAsync();&lt;BR /&gt; dynamic portalSelf = JObject.Parse(json);&lt;/P&gt;&lt;P&gt;var uploadUrl = "http://" + Convert.ToString(portalSelf.urlKey) +&lt;BR /&gt; ".maps.arcgis.com/sharing/rest/content/users/" + owner + "/addItem";&lt;/P&gt;&lt;P&gt;byte[] fileBytes = System.IO.File.ReadAllBytes("C:\\Docs\\animas_AOI_prms\\test\\title_page.pdf");&lt;/P&gt;&lt;P&gt;string strTitle = "Testing 1 2 3";&lt;BR /&gt; using (var formData = new MultipartFormDataContent())&lt;BR /&gt; {&lt;BR /&gt; // Add the HttpContent objects to the form data&lt;BR /&gt; // &amp;lt;input type="text" name="f" /&amp;gt;&lt;BR /&gt; formData.Add(new StringContent("f"), "json");&lt;BR /&gt; formData.Add(new StringContent("token"), strToken);&lt;BR /&gt; formData.Add(new StringContent("async"), "True");&lt;BR /&gt; formData.Add(new StringContent("type"), "PDF");&lt;BR /&gt; formData.Add(new StringContent("title"), strTitle);&lt;BR /&gt; formData.Add(new StringContent("tags"), "eBagis");&lt;BR /&gt; formData.Add(new StringContent("description"), "upload from BAGIS");&lt;BR /&gt; formData.Add(new ByteArrayContent(fileBytes, 0, fileBytes.Count()), "PDF Test", "title_page.pdf");&lt;/P&gt;&lt;P&gt;// Invoke the request to the server&lt;BR /&gt; // equivalent to pressing the submit button on&lt;BR /&gt; // a form with attributes (action="{url}" method="post")&lt;BR /&gt; response = await new EsriHttpClient().PostAsync(url, formData);&lt;BR /&gt; json = await response.Content.ReadAsStringAsync();&lt;BR /&gt; }&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;I found &lt;A _jive_internal="true" href="https://community.esri.com/message/762897-how-do-i-batch-upload-images-to-agol?q=batch%20uploa"&gt;this Python script&lt;/A&gt; and think I am doing the same thing in C#, any ideas?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 05 Nov 2019 00:22:12 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/add-pdf-document-item-to-organizational-portal/m-p/813438#M2442</guid>
      <dc:creator>LesleyBross1</dc:creator>
      <dc:date>2019-11-05T00:22:12Z</dc:date>
    </item>
    <item>
      <title>Re: Add PDF document (item) to organizational portal</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/add-pdf-document-item-to-organizational-portal/m-p/1029804#M6242</link>
      <description>&lt;P&gt;I still haven't been able to get past the&amp;nbsp;&lt;SPAN&gt;502 Bad Gateway error but wanted to bump this issue back to the top and add my current code. I did find some mistakes in my previous submission. Hopefully someone has been able to get this function to work in the last year or so?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;var myPortal = ArcGISPortalManager.Current.GetActivePortal();&lt;BR /&gt;string strToken = myPortal.GetToken();&lt;BR /&gt;var owner = myPortal.GetSignOnUsername();&lt;BR /&gt;var url = $"&lt;A href="https://www.arcgis.com/sharing/rest/portals/self?f=json&amp;amp;token=" target="_blank"&gt;https://www.arcgis.com/sharing/rest/portals/self?f=json&amp;amp;token=&lt;/A&gt;" + strToken;&lt;BR /&gt;var response = new EsriHttpClient().Get(url);&lt;BR /&gt;var json = await response.Content.ReadAsStringAsync();&lt;BR /&gt;dynamic portalSelf = JObject.Parse(json);&lt;/P&gt;&lt;P&gt;var uploadUrl = "https://" + Convert.ToString(portalSelf.urlKey) +&lt;BR /&gt;".maps.arcgis.com/sharing/rest/content/users/" + owner + "/addItem";//convert filestream to byte array&lt;BR /&gt;byte[] fileBytes;&lt;BR /&gt;using (var fileStream = File.OpenRead("C:\\Docs\\animas_AOI_prms\\maps_publish\\title_page.pdf"))&lt;BR /&gt;{&lt;BR /&gt;var binaryReader = new BinaryReader(fileStream);&lt;BR /&gt;fileBytes = binaryReader.ReadBytes((int)fileStream.Length);&lt;BR /&gt;}&lt;BR /&gt;var fileBinaryContent = new ByteArrayContent(fileBytes);&lt;/P&gt;&lt;P&gt;string strTitle = "Testing 1 2 3";&lt;/P&gt;&lt;P&gt;using (var formData = new MultipartFormDataContent())&lt;BR /&gt;{&lt;BR /&gt;// Add the HttpContent objects to the form dataformData.Add(new StringContent("json"), "f");&lt;BR /&gt;formData.Add(new StringContent(strToken), "token");&lt;BR /&gt;formData.Add(new StringContent("true"), "async");&lt;BR /&gt;formData.Add(new StringContent("PDF"), "type");&lt;BR /&gt;formData.Add(new StringContent(strTitle), "title");&lt;BR /&gt;formData.Add(new StringContent("eBagis"), "tags");&lt;BR /&gt;formData.Add(new StringContent("upload from BAGIS"), "description");&lt;BR /&gt;var multipartContent = new MultipartFormDataContent&lt;BR /&gt;{&lt;BR /&gt;{ fileBinaryContent, "file" }&lt;BR /&gt;};&lt;BR /&gt;formData.Add(multipartContent);&lt;/P&gt;&lt;P&gt;// Invoke the request to the server&lt;BR /&gt;// equivalent to pressing the submit button on&lt;BR /&gt;// a form with attributes (action="{url}" method="post")&lt;BR /&gt;response = await new EsriHttpClient().PostAsync(uploadUrl, formData);&lt;BR /&gt;json = await response.Content.ReadAsStringAsync();&lt;BR /&gt;}&lt;/P&gt;</description>
      <pubDate>Tue, 23 Feb 2021 22:21:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/add-pdf-document-item-to-organizational-portal/m-p/1029804#M6242</guid>
      <dc:creator>LesleyBross1</dc:creator>
      <dc:date>2021-02-23T22:21:45Z</dc:date>
    </item>
  </channel>
</rss>

