SOLVED

Download image from news list, getpreview.ashx

%3CLINGO-SUB%20id%3D%22lingo-sub-511318%22%20slang%3D%22en-US%22%3EDownload%20image%20from%20news%20list%2C%20getpreview.ashx%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-511318%22%20slang%3D%22en-US%22%3E%3CP%3EWe%20need%20to%20download%20content%20and%20images%20from%20our%20Sharepoint%20news%20items%20to%20put%20these%20into%20our%20kiosk%20solution.%20Getting%20the%20text%20from%20the%20items%20is%20simple%20however%20for%20the%20images%20we%20cannot%20find%20where%20they%20are%20stored.%20All%20images%20for%20a%20news%20item%20(and%20other%20pages)%20are%20consumed%20and%20stored%20somewhere%20and%20then%20rendered%20in%20sharepoint%20via%26nbsp%3Blayouts%2F15%2Fgetpreview.ashx%3F%20which%20has%20a%20webguid%2C%20siteguid%20and%20file%20guid%20passed%20as%20parameters.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3Emy%20question%20is%20twofold%2C%20where%20are%20the%20images%20saved%20-%20in%20a%20hidden%20list%20somewhere%3F%20-%20we%20cant%20find%20one.%3C%2FP%3E%3CP%3Eis%20is%20possible%20to%20download%20an%20image%20via%20some%20mechanism%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-642983%22%20slang%3D%22en-US%22%3ERe%3A%20Download%20image%20from%20news%20list%2C%20getpreview.ashx%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-642983%22%20slang%3D%22en-US%22%3E%3CP%3Enot%20an%20ideal%20solution%2C%20but%20its%20the%20best%20we%20could%20come%20up%20with...%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%24userName%20%3D%20%22username%22%3CBR%20%2F%3E%24password%20%3D%20%22pwd%22%3CBR%20%2F%3E%24pageUrl%20%3D%20%22%3CA%20href%3D%22https%3A%2F%2Fxxx.sharepoint.com%2F_layouts%2F15%2Fgetpreview.ashx%3FguidSite%3D2bdaba4a-9050-4df1-a642-xxxxxxecfc%26amp%3BguidWeb%3Dbb46b281-1410-4eff-8256-2fe997a63560%26amp%3BguidFile%3D2aebd28b-d5e6-4885-a7b5-1dc455ed44e4%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fxxx.sharepoint.com%2F_layouts%2F15%2Fgetpreview.ashx%3FguidSite%3D2bdaba4a-9050-4df1-a642-xxxxxxecfc%26amp%3BguidWeb%3Dbb46b281-1410-4eff-8256-2fe997a63560%26amp%3BguidFile%3D2aebd28b-d5e6-4885-a7b5-1dc455ed44e4%3C%2FA%3E%22%3C%2FP%3E%3CP%3E%3CBR%20%2F%3E%24image%20%3D%20%22c%3A%5Cjunk%5Csomeimage.jpg%22%3C%2FP%3E%3CP%3E%23create%20secure%20password%3CBR%20%2F%3E%24sPassword%20%3D%20%24password%20%7C%20ConvertTo-SecureString%20-AsPlainText%20-Force%3C%2FP%3E%3CP%3E%24webClient%20%3D%20New-Object%20System.Net.WebClient%3CBR%20%2F%3E%24webClient.Credentials%20%3D%20New-Object%20Microsoft.SharePoint.Client.SharePointOnlineCredentials(%24userName%2C%20%24sPassword)%3CBR%20%2F%3E%24webClient.Headers.Add(%22X-FORMS_BASED_AUTH_ACCEPTED%22%2C%20%22f%22)%3CBR%20%2F%3E%24webClient.DownloadFile(%24pageUrl%2C%20%24limage)%3CBR%20%2F%3E%24webClient.Dispose()%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-686698%22%20slang%3D%22en-US%22%3ERe%3A%20Download%20image%20from%20news%20list%2C%20getpreview.ashx%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-686698%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F76441%22%20target%3D%22_blank%22%3E%40David%20Bargna%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ENews%20posts%20create%20a%20new%20folder%20in%20your%20Site%20Assets%20library%20-%20which%20contain%20the%20images%20associated%20with%20that%20news%20post.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EQuestion%201.%20Go%20to%20Site%20Assets%20%26gt%3B%20Site%20Pages%20%26gt%3B%20Folder%20with%20your%20news%20post's%20title.%20There%20you'll%20find%20the%20images%20associated%20with%20that%20news%20post.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EQuestion%202.%20You%20can%20use%20PowerShell%20to%20grab%20that%20item%20(the%20image)%20and%20download%20the%20filestream%20then%20write%20it%20to%20your%20disk.%20You%20can%20also%20download%20through%20the%20UI.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-689740%22%20slang%3D%22en-US%22%3ERe%3A%20Download%20image%20from%20news%20list%2C%20getpreview.ashx%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-689740%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F241707%22%20target%3D%22_blank%22%3E%40Thomas%20Berman%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3Ethanks%2C%20that's%20we%20assumed%2C%20however%20we%20have%2070%20news%20posts%2C%20and%20only%202%20site%20assets%20folders%2C%20some%20images%20are%20stored%20in%20the%20'images'%20folder.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3Ethe%20solution%20we%20came%20up%20works%20well%2C%20as%20we%20can%20specify%20the%20image%20size%20to%20download%20and%20send%20to%20our%20kiosk%20system%20via%20powershell%20without%20having%20to%20worry%20about%20the%20original%20location%20of%20the%20image.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3Ejust%20for%20completion%2C%20here%20is%20the%20script%20to%20download%20images%2C%20metadata%20and%20stick%20them%20into%20a%20json%20which%20are%20kiosk%20consumes.%3C%2FP%3E%3CDIV%3E%3CFONT%3E%23start%3CBR%20%2F%3E%24cred%20%3D%20New-Object%20System.Management.Automation.PsCredential%20....%3CBR%20%2F%3EConnect-PnPOnline%20'%3CA%20href%3D%22https%3A%2F%2Fxxxxxx.sharepoint.com%2Fsites%2Fnews%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fxxxxxx.sharepoint.com%2Fsites%2Fnews%3C%2FA%3E'%20-Credentials%20%24cred%3CBR%20%2F%3E%23kiok%20json%3CBR%20%2F%3E%24simple_json%3D%40%7B%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%20%22lang%22%3D%22en%22%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%20%22featured%22%3D%24true%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%20%22subtitle%22%3D%24title%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%20%22description%22%3D%24desc%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%20%22links%22%3D%24url%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%20%22contacts%22%3D%24contactemail%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%20%22visuals%22%3D%40%7B%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%22public%20images%22%3D%40%7B%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%22hide%22%3D%24false%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%22id%22%3D%24imageurl%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%22main_visual%22%3D%24true%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%7D%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%7D%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%20%22release_date%22%3D%24date%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%20%22title%22%3D%24title%3CBR%20%2F%3E%7D%3C%2FFONT%3E%3C%2FDIV%3E%3CDIV%3E%3CFONT%3E%26nbsp%3B%3CBR%20%2F%3E%24webClient%20%3D%20New-Object%20System.Net.WebClient%3CBR%20%2F%3E%24webClient.Credentials%20%3D%20New-Object%20Microsoft.SharePoint.Client.SharePointOnlineCredentials(%24cred.UserName%2C%24cred.password%20)%3CBR%20%2F%3E%24webClient.Headers.Add(%22X-FORMS_BASED_AUTH_ACCEPTED%22%2C%20%22f%22)%3CBR%20%2F%3E%24rootpath%3D%22%5C%5Csomewhere%5C%22%3CBR%20%2F%3E%24stuff%3D%40()%3CBR%20%2F%3E%23get%20items%3CBR%20%2F%3EForeach%20(%24item%20in%20%24newslist)%3CBR%20%2F%3E%7B%3CBR%20%2F%3E%26nbsp%3B%20%23%20desctription.%3CBR%20%2F%3E%26nbsp%3B%20if%20(%24item.FieldValues.Description%20-ne%20%24null)%7B%3CBR%20%2F%3E%26nbsp%3B%20%23http%20content.%3CBR%20%2F%3E%26nbsp%3B%3CBR%20%2F%3E%26nbsp%3B%20%24simple_json.description%3D%24item.FieldValues.Description%3CBR%20%2F%3E%26nbsp%3B%20%24simple_json.title%3D%24item.fieldvalues.Title%3CBR%20%2F%3E%26nbsp%3B%20%24simple_json.visuals.'public%20images'.id%3D%22%24rootpath%24(%24item.fieldvalues.Title).jpg%22%3CBR%20%2F%3E%26nbsp%3B%20%24webClient.DownloadFile(%24item.FieldValues.BannerImageUrl.Url%2C%20%22%24rootpath%24(%24item.fieldvalues.Title).jpg%22)%3CBR%20%2F%3E%24stuff%2B%3D%24simple_json%3CBR%20%2F%3E%26nbsp%3B%3CBR%20%2F%3E%26nbsp%3B%7D%3CBR%20%2F%3E%7D%3CBR%20%2F%3E%24webClient.Dispose()%3CBR%20%2F%3E%24stuff%20%7C%20ConvertTo-Json%20%7COut-File%20kiosk.json%26nbsp%3B%20-Encoding%20utf8%3C%2FFONT%3E%3C%2FDIV%3E%3C%2FLINGO-BODY%3E
Highlighted
Contributor

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 are stored. All images for a news item (and other pages) are consumed and stored somewhere and then rendered in sharepoint via layouts/15/getpreview.ashx? which has a webguid, siteguid and file guid passed as parameters.

 

my question is twofold, where are the images saved - in a hidden list somewhere? - we cant find one.

is is possible to download an image via some mechanism?

3 Replies
Highlighted

not an ideal solution, but its the best we could come up with... 

 

$userName = "username"
$password = "pwd"
$pageUrl = "https://xxx.sharepoint.com/_layouts/15/getpreview.ashx?guidSite=2bdaba4a-9050-4df1-a642-xxxxxxecfc&g..."


$image = "c:\junk\someimage.jpg"

#create secure password
$sPassword = $password | ConvertTo-SecureString -AsPlainText -Force

$webClient = New-Object System.Net.WebClient
$webClient.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($userName, $sPassword)
$webClient.Headers.Add("X-FORMS_BASED_AUTH_ACCEPTED", "f")
$webClient.DownloadFile($pageUrl, $limage)
$webClient.Dispose()

Highlighted

@David Bargna 

 

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.

Best Response confirmed by David Bargna (Contributor)
Solution

@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