Shouldn't IconImageMBS and IconMaskMBS work on Web?

I have tried it with both files and folders, but IconImageMBS and IconMaskMBS are returning a nil picture inside a WebApp (I tried on macOS):

[code]Dim f As FolderItem = SpecialFolder.Documents
Dim tempPicture As Picture

If f = Nil Or Not f.Exists Then Return

tempPicture = f.IconImageMBS(512) 'tempPicture is nil after this line
tempPicture.Mask = f.IconMaskMBS(512)[/code]

I am using the latest MBS 19.1 beta plugins on the latest Xojo 2018R4. It says Web is OK at: https://www.monkeybreadsoftware.net/iconservice-folderitem-method.shtml

This works fine for desktop apps, returning a valid Picture.

the conversion from NSImage to console picture may not be implemented.

You can try getting NSImageMBS from NSWorkSpace.Icon() function. Than convert to PNG and read back as picture.

This is a Web App that will eventually run on Linux (and maybe macOS/Windows), so macOS only is not enough. Given it works for desktop macOS, I am unsure why Web macOS doesn’t work.

The Web App accepts uploaded files and needs to display the icon image to the user. Will it be fixed sometime?

Please check LinuxIconMBS module.

And maybe you just get your own icon set for the 10 different types you may need.

For a web app, I would also recommend just having a collection of icons and using those. This would offer you a few benefits:

  1. You can rely on it to work every time on every installation
  2. You can be sure exactly what the icon you’re going to display is
  3. You can serve the images from a CDN or static delivery system - this improves speed and the icon won’t have to be generated and sent to the browser for each file

NSImageMBS won’t work on Linux, LinuxIconMBS won’t work on Mac, you’ll need a different plugin for each platform - more code! Take the simple route for this one :wink:

The NSImageMBS suggestion above doesn’t work in a WebApp either. The below code gives a result for tempPicture every time in a Desktop app, but in a macOS Web App it returns nil for all 32 representations:

[code]Dim f As FolderItem = SpecialFolder.Documents
Dim n As NSImageMBS = NSWorkspaceMBS.iconForFile(f)
Dim tempPicture As Picture

Dim reps() As NSImageRepMBS = n.representations
For Each r As NSImageRepMBS In reps
n.removeRepresentation r

Dim nn As New NSImageMBS(r.pixelsWide, r.pixelsHigh)
nn.addRepresentation r

tempPicture = nn.CopyPictureWithMask
If tempPicture <> Nil And tempPicture.Width >= 512 Then
Exit
End If
Next[/code]

As the web app is a console app, I am not sure wether Apple’s Icon functions work. They may need GUI frameworks initialized.

Is there any possible workaround eg a Shell call?

The only alternative I can think of is to launch a desktop app with the file, but this is sub-optimal.

I just implemented NSImage to Picture conversion.
IconImageMBS and IconMaskMBS work.

But IconMBS fails as it combines picture and mask to a new picture which looks like mask with mask.

So I made a feedback case: feedback://showreport?report_id=55303

Most Linux hosts do not have any desktop UI implemented.

I was talking about getting icon in MacOS console app.
Which works in general, but the draw picture fills image with mask by error for me.

I’m hoping LinuxIconMBS will be able to help out on Linux. Is a GUI a requirement to get a file’s icon picture — I would have thought it was stored in the OS with the file or in a library somewhere?

Just try it.
No idea whether it may work.

Sorry, but LinuxIconMBS doesn’t return a picture in Linux Mint (ie has a GUI) in a Web App either. In the code below (borrowed from the LinuxIconMBS example, tempPicture is always nil. I placed this in the Open event.

[code]Dim tempPicture As Picture

// icon for desktop folder
Dim f2 As FolderItem = SpecialFolder.Desktop
tempPicture = LinuxIconMBS.FileIcon(f2, 512)

'// symbolic icon
tempPicture = LinuxIconMBS.SymbolicIcon(“image/jpeg”, 512)[/code]

It may require GUI libraries, so maybe you just do your own icons…