OpenDialog and DropObject: “openable” File Type

  1. 3 weeks ago

    Emile S

    Jul 30 Europe (France, Strasbourg)

    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

  2. @Emile S — 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.

  3. Greg O

    Jul 31 Xojo Inc

    @Emile S 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

    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!!!

  4. 2 weeks ago

    Emile S

    Aug 5 Europe (France, Strasbourg)

    @Greg OLone You should always validate files

    By checking the file embedded magic numbers ?

  5. Greg O

    Aug 5 Xojo Inc

    @Emile S 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.

  6. Emile S

    Aug 5 Europe (France, Strasbourg)

    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).

  7. Greg O

    Aug 7 Xojo Inc

    @Emile S 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).

    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”

or Sign Up to reply!