Forum Discussion
Download image from news list, getpreview.ashx
- Jun 13, 2019
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
News posts create a new folder in your Site Assets library - which contain the images associated with that news post.
Question 1. Go to Site Assets > Site Pages > Folder with your news post's title. There you'll find the images associated with that news post.
Question 2. You can use PowerShell to grab that item (the image) and download the filestream then write it to your disk. You can also download through the UI.
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.
$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