We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
There are a number of solutions developers have come up with to handle this. Would be nice to include commands out of the box.
Reference
function New-MediaItem{ [CmdletBinding()] param( [Parameter(Position=0, Mandatory=$true, ValueFromPipeline=$true)] [ValidateNotNullOrEmpty()] [string]$filePath, [Parameter(Position=1, Mandatory=$true)] [ValidateNotNullOrEmpty()] [string]$mediaPath ) $mco = New-Object Sitecore.Resources.Media.MediaCreatorOptions $mco.Database = [Sitecore.Configuration.Factory]::GetDatabase("master"); $mco.Language = [Sitecore.Globalization.Language]::Parse("en"); $mco.Versioned = [Sitecore.Configuration.Settings+Media]::UploadAsVersionableByDefault; $mco.Destination = "$($mediaPath)/$([System.IO.Path]::GetFileNameWithoutExtension($filePath))"; $mc = New-Object Sitecore.Resources.Media.MediaCreator $mc.CreateFromFile($filepath, $mco); } # Usage example New-MediaItem "C:\Users\Adam\Desktop\Accelerators.jpg" "$([Sitecore.Constants]::MediaLibraryPath)/Images"
function Add-MediaItem { [CmdletBinding()] param( [Parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()] [string]$Path, [Parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()] [string]$Extension, [Parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()] [byte[]]$Content ) $mco = New-Object Sitecore.Resources.Media.MediaCreatorOptions $mco.Database = Get-Database -Name "master" $mco.KeepExisting = $false $mco.Versioned = [Sitecore.Configuration.Settings+Media]::UploadAsVersionableByDefault $mco.Destination = $Path $mc = New-Object Sitecore.Resources.Media.MediaCreator New-UsingBlock ($stream = New-Object System.IO.MemoryStream) { $stream.Write($Content, 0, $Content.Length) $mc.CreateFromStream($stream, ($Path + "." + $Extension), $mco) } }
function Update-MediaItem{ [CmdletBinding()] param( [Parameter(Position=0, Mandatory=$true, ValueFromPipeline=$true)] [ValidateNotNullOrEmpty()] [string]$filePath, [Parameter(Position=1, Mandatory=$true)] [ValidateNotNullOrEmpty()] [string]$mediaPath) [Sitecore.Data.Items.MediaItem]$item = gi $mediaPath [Sitecore.Resources.Media.Media] $media = [Sitecore.Resources.Media.MediaManager]::GetMedia($item); $extension = [System.IO.Path]::GetExtension($filePath); $stream = New-Object -TypeName System.IO.FileStream -ArgumentList $filePath, "Open", "Read" $media.SetStream($stream, $extension); $stream.Close(); } # Usage example - overwrite the image created with previous cmdlet with new image Update-MediaItem "$SitecoreDataFolder\Tchotchkeys.jpg" "$([Sitecore.Constants]::MediaLibraryPath)/Images/Accelerators"
The text was updated successfully, but these errors were encountered:
Should probably keep these as functions to avoid breaking functionality for others.
Sorry, something went wrong.
This issue is stale because it has been open for 365 days with no activity.
This issue was closed because it has been inactive for 30 days since being marked as stale.
No branches or pull requests
There are a number of solutions developers have come up with to handle this. Would be nice to include commands out of the box.
Reference
The text was updated successfully, but these errors were encountered: