Console icon indicating copy to clipboard operation
Console copied to clipboard

Send-file -NoDialog gives "There is no file attached" message

Open JimFokkens opened this issue 7 years ago • 13 comments

Expected Behavior

Send-file -NoDialog should start download of for example a media item attachment to the default download folder on the client.

Actual Behavior

A messagebox "There is no file attached" message is shown. After that the Sitecore back end 'hangs' with the Copy of Download dialog, the abort button is not working, IIS restart is needed to get it up and running again. No info found in the Sitecore logs.

Steps to Reproduce the Problem

Sitecore 8.2, SPE version 4.7.2.26422

Create a subfolder "temp" in the Media Library Upload a file (in this case a Doc, see query in script) in that subfolder. Create a Powershell Script item under /sitecore/system/Modules/PowerShell/Script Library/Media Library Maintenance/Content Editor/Context Menu. I duplicated the existing Download item and replaced the script with the following: $location = get-location; $language = $SitecoreContextItem.Language.Name; Get-Item -Language $language $location | Send-file -NoDialog;

First test the script without the -NoDialog. Right click the media library item, select scripts, Copy of Download.

Of course the -NoDialog could be left out, but I want to download multiple files without having a dialog for every file. There is a solution where the item plus child items are zipped, and the zip file can be downloaded, but in my scenario this results in a 1GB+ file which is not downloadable any more. This could be tweaked by creating multiple zip files that can be downloaded, but again this leaves me with multiple download dialogs.

JimFokkens avatar Apr 09 '18 10:04 JimFokkens

@JimFokkens good discovery! Turns out that Factory.GetDatabase(...).GetItem(...) does not like using an ItemUri for locating items.

We'll need to update the code to use the item ID.

Thank you.

michaellwest avatar Apr 09 '18 19:04 michaellwest

This line is broken: https://github.com/SitecorePowerShell/Console/blob/10e9f168e62f0a3a91a321df8800afdce334b281/Cognifide.PowerShell/Commandlets/Interactive/Messages/DownloadMessage.cs#L45

michaellwest avatar Apr 09 '18 19:04 michaellwest

Using -Verbose you can see that media folders are skipped.

image

michaellwest avatar Apr 10 '18 02:04 michaellwest

@AdamNaj while testing this, the -NoDialog causes the console to never return.

It just stays here: image

michaellwest avatar Apr 10 '18 02:04 michaellwest

Is this fixed?

michaellwest avatar Oct 03 '18 01:10 michaellwest

Hey! Is there any news about it? thanks

alvaropmontenegro avatar Oct 04 '22 20:10 alvaropmontenegro

@alvaropmontenegro I think this was included with 6.3. Can you please give it a test? I'll be releasing 6.4 soon and would like to know that it's addressed.

michaellwest avatar Oct 04 '22 23:10 michaellwest

@michaellwest It's strange, I'm using Sitecore 10.2 and Powershell 6.3, as you can see in the image below, and it's not working:

image

I've created a script to generate many packages and it only downloads the first package, after it, the console never returns and I have to restart the IIS to reset the Sitecore.

part of my script:

image

alvaropmontenegro avatar Oct 05 '22 13:10 alvaropmontenegro

So to be clear, I should test downloading one package, and then downloading many packages in a row. Correct?

michaellwest avatar Oct 05 '22 16:10 michaellwest

Yes, you have to download many packages in a row. It happens in a ForEach loop. E.g: Package_1.zip, Package_2.zip.....

Each package has a lot of items.

Below is a piece of my code, showing the ForEach loop: ` $packages | ForEach-Object {

Write-Host "Preparing Package $counter"
$package = New-Package "Packages";

$package.Sources.Clear();

$package.Name = "package_" + $counter
$package.Metadata.Author = "Alvaro";
$package.Metadata.Publisher = "Powershell";
$package.Metadata.Version = "1.0";
$package.Metadata.Readme = ''

$_.Items | ForEach-Object {
	$source = $_ | New-ItemSource -Name $_.Name -InstallMode Merge
	$package.Sources.Add($source);
}

    $packageName = "package_" + $counter
$packageFileName = "$($packageName).zip"

Export-Package -Project $package -Path $packageFileName -Zip
Send-File -Path "$SitecorePackageFolder\$($package.Name).zip"
Remove-Item "$($SitecorePackageFolder)\$($packageFileName)"

    Write-Host "$packageName done!"

$counter = $counter + 1

} `

If you'd like I can email you the whole script

alvaropmontenegro avatar Oct 05 '22 16:10 alvaropmontenegro

Using the following script where -NoDialog is excluded I'm able to see each of the prompts to download the item and clicking Close or Download (then Close) results in the desired experience.

$counter = 0

while($counter -lt 5) {
    Write-Host "Preparing Package $counter"
    $package = New-Package -Name "Packages"
    
    $package.Sources.Clear();
    
    $package.Name = "package_" + $counter
    $package.Metadata.Author = "Michael West";
    $package.Metadata.Publisher = "Powershell";
    $package.Metadata.Version = "1.0";
    $package.Metadata.Readme = ''
    
    $source = Get-Item 'master:\templates\sample' | New-ItemSource -Name 'Sample Templates' -InstallMode Skip
    $package.Sources.Add($source)
    
    $packageName = "package_" + $counter
    $packageFileName = "$($packageName).zip"
    
    Export-Package -Project $package -Path $packageFileName -Zip
    Send-File -Path "$SitecorePackageFolder\$($package.Name).zip"
    Remove-Item "$($SitecorePackageFolder)\$($packageFileName)"
    
    Write-Host "$packageName done!"
    
    $counter = $counter + 1
}

From here I'll investigate the -NoDialog behavior.

michaellwest avatar Oct 05 '22 17:10 michaellwest

Yes @michaellwest! Nowadays I've excluded the "-NoDialog" and it works well as you described. The problem is only when "-NoDialog" is included. I'd like to use the "-NoDialog" to avoid clicking every time on the Close/Download buttons. Any test or extra information you need, please, let me know. Thank you!

alvaropmontenegro avatar Oct 05 '22 19:10 alvaropmontenegro

Here is what I think is happening.

When running with -NoDialog the job results are never updated with a call to PutMessage. This results in the thread just waiting until something causes it to break a while look. At the moment I think a possible solution would be to still show a dialog but to auto close as soon as the save dialog is closed. There is no native browser feature to report that the dialog closed so we would likely have to go with a cookie to signal that it's closed.

Any solution at this point is likely to be a big effort.

michaellwest avatar Oct 05 '22 21:10 michaellwest