OpenDialog and DropObject: “openable” File Type

I use the same file type set in both codes:

OpenDialog and DropObject (Me.AcceptFileType).

I get two different behavior:
a. OpenDialog let me open only png files (as I was beieved)
b. DropObject let me open all images file (and clear the previous Canvas if it is not an image file).

I used:

FT_Images.All

and

FT_Images.Image_PNG

in both cases, same results.

FWIW.

Xojo 2019r1.1
El Capitan

@Emile Schwarz — I think the drag&drop system tries to convert one type into another, so it will validate the drop if it can convert the image to PNG. But that won’t work with more “exotic” formats.

Opening a file is more picky because its UTI is based on the file’s extension, which is less reliable.

[quote=447759:@Emile Schwarz]I use the same file type set in both codes:

OpenDialog and DropObject (Me.AcceptFileType).

I get two different behavior:
a. OpenDialog let me open only png files (as I was beieved)
b. DropObject let me open all images file (and clear the previous Canvas if it is not an image file).

I used:

FT_Images.All

and

FT_Images.Image_PNG

in both cases, same results.

FWIW.

Xojo 2019r1.1
El Capitan[/quote]
You should always validate files that are dropped or opened anyway as users can change file extensions and applications can set UTIs to whatever they want.

P.S. I recently came across an app that sets one of its output file formats so that macOS thinks it’s a folder, even though it’s not. This made the file show up in SelectFolderDialogs!!!

By checking the file embedded magic numbers ?

Well… in the case of Pictures, when you use Picture.Open, it will return Nil. But you should always build in some error or exception checking in case your import routine doesn’t like what it got.

I understand.

Years ago, I’ve made a mistake when I downloaded some MB of gif/jpg files and do not wanted to make drastic changes in the download process to re-download the files and set them the correct file extension.

I used AppleScript to read the magic numbers (if it is gif change the file type to .gif / if it is jpg, change the file type to jpg) and this worked fine. It was a one shot and do not deserve wasting time to change the project file.

Sometimes after that, I recreated from scratch the download process and take care of that (using the HTTPHeading).

[quote=449062:@Emile Schwarz]I understand.

Years ago, I’ve made a mistake when I downloaded some MB of gif/jpg files and do not wanted to make drastic changes in the download process to re-download the files and set them the correct file extension.

I used AppleScript to read the magic numbers (if it is gif change the file type to .gif / if it is jpg, change the file type to jpg) and this worked fine. It was a one shot and do not deserve wasting time to change the project file.

Sometimes after that, I recreated from scratch the download process and take care of that (using the HTTPHeading).[/quote]
Make sure you are also setting the UTI fields in your File Types. The base one should be “public.png” and Conforms To should probably be “public.image”