Forum Discussion

David Bargna's avatar
David Bargna
Iron Contributor
May 02, 2019
Solved

Download image from news list, getpreview.ashx

We need to download content and images from our Sharepoint news items to put these into our kiosk solution. Getting the text from the items is simple however for the images we cannot find where they ...
  • David Bargna's avatar
    David Bargna
    Jun 13, 2019

    Thomas Berman 

     

    thanks, that's we assumed, however we have 70 news posts, and only 2 site assets folders, some images are stored in the 'images' folder.

     

    the solution we came up works well, as we can specify the image size to download and send to our kiosk system via powershell without having to worry about the original location of the image.

     

    just for completion, here is the script to download images, metadata and stick them into a json which are kiosk consumes.

    #start
    $cred = New-Object System.Management.Automation.PsCredential ....
    Connect-PnPOnline 'https://xxxxxx.sharepoint.com/sites/news' -Credentials $cred
    #kiok json
    $simple_json=@{
       "lang"="en"
       "featured"=$true
       "subtitle"=$title
       "description"=$desc
       "links"=$url
       "contacts"=$contactemail
       "visuals"=@{
        "public images"=@{
          "hide"=$false
          "id"=$imageurl
          "main_visual"=$true
          }
        }
       "release_date"=$date
       "title"=$title
    }
     
    $webClient = New-Object System.Net.WebClient
    $webClient.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($cred.UserName,$cred.password )
    $webClient.Headers.Add("X-FORMS_BASED_AUTH_ACCEPTED", "f")
    $rootpath="\\somewhere\"
    $stuff=@()
    #get items
    Foreach ($item in $newslist)
    {
      # desctription.
      if ($item.FieldValues.Description -ne $null){
      #http content.
     
      $simple_json.description=$item.FieldValues.Description
      $simple_json.title=$item.fieldvalues.Title
      $simple_json.visuals.'public images'.id="$rootpath$($item.fieldvalues.Title).jpg"
      $webClient.DownloadFile($item.FieldValues.BannerImageUrl.Url, "$rootpath$($item.fieldvalues.Title).jpg")
    $stuff+=$simple_json
     
     }
    }
    $webClient.Dispose()
    $stuff | ConvertTo-Json |Out-File kiosk.json  -Encoding utf8

Resources