superlistapp / super_native_extensions

Native drag & drop, clipboard access and context menu.
MIT License
452 stars 79 forks source link

[super_clipboard] Having issues implementing any type file copying #310

Open resucutie opened 8 months ago

resucutie commented 8 months ago

I've been trying to use super_clipboard to copy unspecific files, but I couldn't get it working

final item = DataWriterItem();
item.add(Formats.fileUri(File(filePath).uri));
await SystemClipboard.instance?.write([item]);

On Linux, and presumably on desktop, it just gives a weird file, although uploading on GitHub actually outputs a valid file image
On Android, it crashes and outputs this:

android.os.FileUriExposedException: file:///storage/emulated/0/Syncthing/LocalBooru/files/1000000065.jpg exposed beyond app through ClipData.Item.getUri()
knopp commented 8 months ago

I'm not sure what you trying to accomplish. Copying file URls to clipboard will work differently on each operating system. Also depends on whether the application that you paste into even supports file URLs in the clipboard. On Android this will likely not work at all because of sandboxing.

What exactly is a "weird file"?

resucutie commented 8 months ago

Sorry for the late response! basically i am trying to copy a file to the clipboard that I don't know its extension.
Either way, do you recommend any way to copy to clipboard a local file? I was trying a few solutions but they don't seem to work well, or fail on the weird Discord bug that I showed

resucutie commented 8 months ago

Also forgot to inform what did I meant with weird file. When I tried to copy with whatever implementation I had and pasted it on an application like Discord, it would give the result that I've shown on image. I also tried to paste on the a GitHub issue writer (where you write the issue, idk if it even has a name) and the file was able to load. I was confused in some way

resucutie commented 8 months ago

Also forgot to inform what did I meant with weird file. When I tried to copy with whatever implementation I had and pasted it on an application like Discord, it would give the result that I've shown on image. I also tried to paste on the a GitHub issue writer (where you write the issue, idk if it even has a name) and the file was able to load. I was confused in some way

On a second thought, this may have been caused due to sandboxing on Flatpak applications, since on Linux systems it copies as a file path. I may gonna test it out better using Formats.jpeg or something. Unless you have a different solution

resucutie commented 8 months ago

After checking out, apparently using Formats.jpeg was working on Android, but not on Linux. Do you have any idea why?

final item = DataWriterItem();
item.add(Formats.jpeg(await File(image.path).readAsBytes()));
await SystemClipboard.instance?.write([item]);
resucutie commented 8 months ago

After doing some testing, apparently it only copies .png files on Linux. Is that intentional or a Linux fluke?

knopp commented 8 months ago

You can write anything in the clipboard - important thing is what the target application supports. If application that you're pasting into only supports PNG then only PNG will work.

resucutie commented 8 months ago

forgot to reply but it seems to copy images now. imma test videos whenver i implement on my application. as of now i'll close this

resucutie commented 6 months ago

i've found out that copying videos does not work, at least on linux. doing item.add(Formats.mp4(await File(image.path).readAsBytes())) does not result in a video copied.

for GIFs, it just yeets a static image

resucutie commented 6 months ago

the same behavior can be observed for dragging and dropping