jvsteiner / s3-image-uploader

MIT License
31 stars 14 forks source link

[Feature Request] Support mobile attachments #29

Open MahmadSharaf opened 4 months ago

MahmadSharaf commented 4 months ago

Hello there,

I wonder if it is possible that the plugin supports uploading attachments from mobile.

jvsteiner commented 4 months ago

I've had this request before. I don't know how to do it properly. It worked at one time, and then it stopped. There have been some suggestions on how to debug it, which I tried, but didn't manage to get anything working. It's also harder because I don't even have an android phone to test.

MahmadSharaf commented 4 months ago

Okay, let me try

MahmadSharaf commented 4 months ago

Okay, what I have deduced so far:

  1. It is not a mobile related problem. The plugin doesn't handle "Insert attachment" command in general.
  2. This command opens a file picker, saves it in the vault, and creates a Wiki-link for it.

Solutions I tried in so far with no luck:

  1. Intercept the callback function of the file picker and pass the file to your PasteFunction
  2. Override the native command and a custom functionality, which opens the file picker and then pass the file to the PasteFunction
async onload() {
...
...
...
   // Wait for Obsidian to load everything, so we make sure that the "Insert attachment" is created by Obsidian
    this.app.workspace.onLayoutReady(() => {
        // Get the command
        const attachFileCommandDefinition = this.app.commands?.commands?.["editor:attach-file"];
       // Store the original callback
        const attachFileCallback = attachFileCommandDefinition?.editorCallback;
        // Check if the callback is stored as expected
        if (typeof attachFileCallback === "function") {
            // Override the existing command with the new callback
            this.app.commands.removeCommand(attachFileCommandDefinition .id);
            this.addCommand({
                id: "editor:insert-attachment",
                name: "Insert Attachment",
                editorCallback: newCallback,
            });
    }
}

I am sharing the progress, in case you have any hint on how to proceed. Meanwhile, I am looking into it.

jvsteiner commented 4 months ago

maybe some inspiration here? https://github.com/trganda/obsidian-attachment-management/blob/main/src/main.ts

MahmadSharaf commented 4 months ago

Yes, I installed it, but unfortunately it doesn't support attachments via the command. But I will look into that direction, I might get inspired from other plugins.

jvsteiner commented 4 months ago

It is not a mobile related problem. The plugin doesn't handle "Insert attachment" command in general.

this might be the key insight

Parrrdo commented 1 week ago

Maybe you can find a solution from this project (inspired by yours),https://github.com/seebin/obsidian-minio-uploader-plugin

jvsteiner commented 5 days ago

So, I have spent some more time investigating this popular request. I would like to support it, however, unfortunately, my existing code path is frankly a pigs breakfast. While it would be easy to make "something happen" it would be a lot harder to support all of the configuration options that are present in the existing upload mechanism. This would require me to refactor it substantially. Perhaps I am just looking for justifications for my laziness, but another issue came to mind. In the existing cut and paste insert workflow, the user has implicitly decided exactly where in the note that the image/file to be uploaded should go - that's where the cursor is at in the current note. If I understand the workflow for mobile, its a bit different. This would enable it to be added from the share menu, or from the camera roll, etc. In this case, I don't know where in which note to actually put the link.

For those of you following this issue - do you have any desired behavior, or insight into to how it actually should work? Remember, I don't need or use this feature, so I don't have any clue how you might want it to work. Please do explain.

MahmadSharaf commented 1 day ago

Thank you for giving it another shot.

Here is my mobile workflow:

  1. My daily note contains all my life management, so any input I take mostly taken from my mobile.
  2. Sometimes, I need to add a photo taken by mobile camera.
  3. So I open the note, insert the cursor at the location
  4. Then, execute "Insert Attachment" command either from command palette or from context menu.

The problem is that the plugin doesn't intercept this action. Also, the mobile app doesn't support Copy/Paste or Drag and Drop actions.

What I tried so far, knowing that I have no JS experience nor Obsidian API:

  1. Intercept the built-in command function right after the file picker. So that the plugin handles the placement as usual.
  2. Replace the built-in function while maintaining the same command name for convenience. For example, in my personal use case, I use slash commander that already has "Insert Attachment" command, also Commander plugin that could place a button to trigger the command anywhere. Although it is just for convenience but not big deal
  3. The last option, that I couldn't do at all, is to implement the full functionality, which is a file picker and handle the placement of the attachment as usual

I hope you would have a much better luck, and be able to implement this feature.