Giter VIP home page Giter VIP logo

Comments (13)

knopp avatar knopp commented on September 17, 2024 1

I just tested this and it seems that the file promise metadata outlook uses is different than what standard NSFilePromiseProvider produces. I'll post update soon.

from super_native_extensions.

knopp avatar knopp commented on September 17, 2024 1

Can you try this with super_drag_and_drop 0.2.3+1?
Formats.pdf should work for PDF file.

from super_native_extensions.

knopp avatar knopp commented on September 17, 2024 1

In this case you will need to check if the format is FileFormat and then cast it to FileFormat.

if (format is FileFormat) {
   final fileFormat = format as FileFormat;
}

from super_native_extensions.

knopp avatar knopp commented on September 17, 2024 1

Right. We're likely missing a FileFormat for public.html. The value format is meant for copying and pasting rich text, which is treated as value (and needs additional conversion of some platforms).

As for generic access - you should be able to use DataReader.platformFormats to get all available formats and then construct SimpleFileFormat(fallbackFormats:[firstPlatformFormat]).

This might be a common enough use case to just support it out of box. You can try something like this (I haven't tested the code):

extension on DataReader {
  raw.ReadProgress? getAnyFile(
    AsyncValueChanged<DataReaderFile> onFile, {
    ValueChanged<Object>? onError,
  }) {
    final formats = platformFormats;
    if (formats.isNotEmpty) {
      final format = formats.first;
      return getFile(
        SimpleFileFormat(fallbackFormats: [format]),
        onFile,
        onError: onError,
      );
    } else {
      return null;
    }
  }
}

from super_native_extensions.

knopp avatar knopp commented on September 17, 2024

It is possible that outlook uses file promises (aka virtual files) in which case there is no URL and you will need to read file content instead through getFile(format).

from super_native_extensions.

socramm9 avatar socramm9 commented on September 17, 2024

How to know the correct format? I tried using a pdf and hardcode Formats.pdf but getFile returns null

If no file for given format is available, null progress is returned and the [onFile] block will not be called.

from super_native_extensions.

socramm9 avatar socramm9 commented on September 17, 2024

I think it works now. I am not done testing yet. Tanks allot for your fast Support.

One more thing not sure if is an issue or I am doing it wrong. But I have to pass the FileFormat to the getFile method. But for that I would need to know the format from reader. This is what I tried:
Bildschirm­foto 2023-03-14 um 16 35 37

It gets the correct format but the return type is not supported by getFile

Bildschirm­foto 2023-03-14 um 16 38 53

Bildschirm­foto 2023-03-14 um 16 35 51

from super_native_extensions.

socramm9 avatar socramm9 commented on September 17, 2024

Okay got it know the issue was also that I had to import FileFormat from super_clipboard

from super_native_extensions.

knopp avatar knopp commented on September 17, 2024

Okay got it know the issue was also that I had to import FileFormat from super_clipboard

That seems like a oversight. FileFormat should be reexported by super_drag_and_drop. I'll look into that.

from super_native_extensions.

socramm9 avatar socramm9 commented on September 17, 2024

It seams that not all formats can be handled using getFormats null is returned if I want to drag an .yaml file from outlook.

For my use case I only need the file path is there a way to get the file path whitout having to call getFile? Or would I need to implement all types that are not yet implemented?

For example:

const yaml = SimpleFileFormat(
  uniformTypeIdentifiers: ['public.yaml'],
  mimeTypes: ['application/yaml'],
);
onPerformDrop: (event) async {
    final item = event.session.items.first;

    // data reader is available now
    final reader = item.dataReader!;

    if (reader.canProvide(Formats.fileUri)) {
        reader.getValue<Uri>(
            Formats.fileUri,
            (value) async {
                if (value != null) {
                    await showUploadDialog(
                        context: context,
                       filePath: value.toFilePath(),
                    );
                }
            },
            onError: (error) {
                print('Error reading value $error');
            },
    );
    return;
    }

    final format = reader.getFormats([yaml, ...Formats.standardFormats]).firstOrNull;
    print("MD. $format");

    if (format is FileFormat) {
        reader.getFile(
            format,
            (value) async {
               if (value is DataReaderVirtualFileAdapter) {
                   final file = value.file as VirtualFileFromFile;

                   print("MD. value ${file.file.path} ");

                   await showUploadDialog(
                       context: context,
                       filePath: file.file.path,
                   );
               }
           },
           onError: (error) {
               print("MD. error $error");
            },
        );
        return;
    }
}

from super_native_extensions.

knopp avatar knopp commented on September 17, 2024

You can create the Format definitions that you're missing. If you give me a list of formats that you are missing I can add them to super_native_extensions. I'd like the default list to be as comprehensive as possible.

Btw. yaml on other platforms will be reported as text/x-yaml (even though that's a deprecated definition).

from super_native_extensions.

socramm9 avatar socramm9 commented on September 17, 2024

Btw. yaml on other platforms will be reported as text/x-yaml (even though that's a deprecated definition).

Strange I don't get anything from yaml files. But it works fine if I add my own definition;

If you give me a list of formats that you are missing I can add them to super_native_extensions.

You could add Types for all types of code files: .dart, .ts, .js, .dart, ...

But If possible I would need a more generic approach. I have to support all types of files no matter what. :(

I also had issue whit .html files it was not returning FileFormat but ValueFormat so I tried using getValue, but the value returned from callback was null

from super_native_extensions.

socramm9 avatar socramm9 commented on September 17, 2024

Yes it works thanks allot!

from super_native_extensions.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.