Git Product home page Git Product logo

s3-image-uploader's Introduction

S3 Image Uploader

This is a plugin for Obsidian. It was generated based on the standard plugin template.

This project implements an image uploader, similar to others offered by the community, with one important difference: you can provide your own s3 based storage, instead of relying on a third party service, such as imgur.

This plugin is supported by advertisements.

Note: this plugin is still in development, and there may be some bugs. Please report any issues you find.

It was inspired by the awesome Markdown editor, Typora, and the following Obsidian plugins:

Usage

You have to set up your own s3 bucket, and provide the following information to the plugin:

  • accessKeyId: the access key ID for an s3 user with write access to your bucket
  • secretAccessKey: the secret access key for the s3 user
  • region: the region of your bucket
  • bucket: the name of your bucket (must already exist)
  • folder: the folder in your bucket where you want to store the images (optional, and will be created on the fly if it does not exist.)

If you want others to be able to view the images, you need to make your bucket world readable. You can do this by adding the following policy to your bucket:

{
	"Version": "2008-10-17",
	"Statement": [
		{
			"Sid": "PublicReadGetObject",
			"Effect": "Allow",
			"Principal": "*",
			"Action": "s3:GetObject",
			"Resource": "arn:aws:s3:::<your-bucket>/*"
		}
	]
}

You also need to set up a CORS policy for the bucket:

[
	{
		"AllowedHeaders": ["*"],
		"AllowedMethods": ["GET", "PUT", "POST", "DELETE"],
		"AllowedOrigins": ["*"],
		"ExposeHeaders": []
	}
]

You also need to set up a user with write access to your bucket. You can do this by creating a new user in the IAM console, and attaching the AmazonS3FullAccess policy to it. More granular access control policies are possible, but this is the simplest way to get started.

When you paste an image from the clipboard into the Obsidian note, the plugin will upload the image to your bucket, and insert a link to the image in your note. The link will be of the form https://<your-bucket>.s3.<your-region>.amazonaws.com/<your-optional-folder>/<image-name>. If you have made your bucket world readable, you can share the link with others, and they will be able to view the image.

If you select the "Upload on drag" option in the plugin settings, the plugin will also upload images that you drag into the note - as well as video, audio files and pdfs. This is useful if you want to upload these media from your file system.

If you do not want this behavior in all notes, you can customize it on a per note basis.

  1. You can add an uploadOnDrag YAML frontmatter tag to the note, as seen below.
  2. You can also set the localUpload option to true, which will copy the images to a folder in your local file system, instead of uploading them to the cloud, overriding the global setting.
  3. You can also set note specific folder where the images will be uploaded to, by adding the localUploadFolder option to the YAML frontmatter. This overrides the global setting.

These settings override the global settings. The uploadOnDrag tag affects both S3 and local uploads. The other two options only affect local uploads.

---
uploadOnDrag: true
localUpload: true
localUploadFolder: "my-folder"
---

Development

PR's are welcome, features that I would like to add include:

  • Add support for other cloud storage providers, such as Google Drive, Dropbox, etc.
  • Add support for copying images to a configurable folder in the local file system, instead of uploading them to the cloud.
  • Add support for dynamically moving images between the options above, through hotkeys.
  • Add support for automatically creating buckets if they do not exist.
  • Add support for s3 compatible storage
  • Add support for video, audio, and pdf upload and embedding.

Releasing new releases

Update your manifest.json with your new version number, such as 1.0.1, and the minimum Obsidian version required for your latest release.

Update your versions.json file with "new-plugin-version": "minimum-obsidian-version" so older versions of Obsidian can download an older version of your plugin that's compatible.

Create new GitHub release using your new version number as the "Tag version". Use the exact version number, don't include a prefix v. See here for an example: https://github.com/obsidianmd/obsidian-sample-plugin/releases

Upload the files manifest.json, main.js, styles.css as binary attachments. Note: The manifest.json file must be in two places, first the root path of your repository and also in the release.

Publish the release.

You can simplify the version bump process by running npm version patch, npm version minor or npm version major after updating minAppVersion manually in manifest.json. The command will bump version in manifest.json and package.json, and add the entry for the new version to versions.json

s3-image-uploader's People

Contributors

affix avatar ckt1031 avatar iammatthias avatar jvsteiner avatar kilingzhang avatar mahmadsharaf avatar nicksmith53 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

s3-image-uploader's Issues

Upload is not triggered

Hi, I'm trying to move my attachments from obsidian vault to self-hosted S3 compatible object.
I use Obsidian 1.5.8 on macOS 14.3.1 with s3-image-uploader v0.2.8.

I installed and configured plugin, checked dev console, but pasting or drag and dropping an image or PDF doesn't work.
There is no network activity or errors/warnings in console.
File is just handled as usual, with local copying to attachments folder.
Is seems like some event is not being handled when I'm adding file to note.

I tried other plugins similar to this and file upload is triggered correctly.
Maybe it's related somehow to newer version of Obsidian?

Concurrent uploads

Currently if you want to add multiple images they need to be attached individually. Is it possible drag-and-drop multiple images, or a folder?

Is it possible to upload image with its original name

Thank you for the awesome plugin, it is very convenient. I have been using it for aw while at found a difficulty in maintenance. For example, the image got uploaded but I lost the autogenerated url for some reason. In that case, it is so hard to find this image.

Another case, if I would like to uploaded an already existing one.

Uploading on iOS version

Hi, on desktop this plugin work great!
I tried it on iOS 17.3.1 and I can't get it to work.
Similar to #9
I can record video to show my exact steps.

I used three methods:

Share option from Apple Photos app.

In this case I see dialog like on screenshot below. Selecting import to vault just adds attachment, doesn't trigger plugin. I shared photo which is in heic format with Live Photo if it changes things 🤔
image

Copy photo from Apple Photos app

Same as before but in share dialog I selected "Copy photo".
Pasting it in note does nothing. I mean it's no op, nothing happens or there is no indication. Same as I would be using empty clipboard I guess.

Attaching photo from obsidian

I used attachment icon on Obsidian toolbar and selected same photo as in two previous examples.
It attaches like without plugin, photo goes to attachment folder like in first variant I described.
I also tried attaching not from photo library but png from files dialog, same result.

Powerpoint embedding doesn't work with local upload

As far as I can tell, this is a limitation imposed by the embedding script. There might not be much that can be done about it, unless another approach to render the file is found. I am leaving this issue open to document the shortcoming.

A better UX Google PDF Viewer

I found that it is possible to preview the PDF in a less cluttered way using Google's PDF viewer. It is exactly as your current approach but add ?embedded=true.

<iframe frameborder=0 border=0 width=100% height=480
src="https://docs.google.com/viewer?embedded=true&url={Document}">
</iframe>
  • Current approach:
    image

  • Suggested approach
    image

Specifying S3 upload folder per note not working

Hello there again,

This plugin streamlines my workflow and I cannot emphasize enough how awesome it is.

One particular functionality, so crucial for me that I cannot work without, has been failing. Although I fixed it at my side, I wanted to help as well.

Since the last release, the functionality for setting an S3 upload folder per note is not working any more. I found the problem to be in the below piece of code

let folder = "";
if (localUpload) {
  folder = (_a2 = fm == null ? void 0 : fm.folder) != null ? _a2 : this.settings.localUploadFolder;
} else {
  folder = (_b2 = fm == null ? void 0 : fm.folder) != null ? _b2 : this.settings.folder;
}

My understanding is that code has the logic for two functionalities at the same time:

  1. Whether to save media locally in the vault.
    • If settings flag localUpload is set to True, this means that the user wants the plugin to save all media files locally in the vault.
    • Then it checks where to save the folder locally,
      • If the note's frontmatter property folder exists or has a value. Then save it there.
      • If it is empty, then check for the settings value localUploadFolder.
  2. Or upload it remotely on S3
    • If flag localUpload is set to False, this means that the user wants the plugin to upload all media to S3.
    • Then it checks where to upload the folder on S3.
      • If the note's frontmatter property folder exists or has a value. Then upload to it there
      • If not, then upload to the location specified in setting value folder.

Where it fails?

  1. Frontmatter property folder is not stated anywhere in the settings, or what its functionality is.
  2. Frontmatter Boolean property uploadLocal is hinted in Settings page. So that to be used to override whether to save the media locally or not, but it is not used in the code at all.
  3. Frontmatter property uploadFolder is hinted in Settings page. So that to be used to specify where to save the media locally, but it is not used in the code at all.
  4. It is not possible to specify S3 upload folder.

I believe the code could be altered as below to fix the problems

let folder = "";
if (localUpload || fm.uploadLocal) {
  folder = (_a2 = fm == null ? void 0 : fm.uploadFolder) != null ? _a2 : this.settings.localUploadFolder;
} else {
  folder = (_b2 = fm == null ? void 0 : fm.localUploadFolder) != null ? _b2 : this.settings.folder;
}

If that works, it is worth mentioning the frontmatter property that specifies S3 upload folder per note in the settings, or where you see best fit.

Feature request: PDF upload

Hi!! LOVING the plugin so far - this is flawless and immensely useful. I was wondering if we could get support for other file formats, like pdfs, etc. I have a lot of pdfs and it would be great to embed them directly and upload to s3! Maybe a configurable list of file formats we can upload?

Thanks so much for this plugin, it's incredible

Problems With Instructions 🫤🤯

Hey there -

I love the idea of using s3 for my images, but unfortunately, I don't have a PhD in coding. :/ I spent two hours just trying to figure out the policy and JSON and ended up giving up. I do know enough about coding to be dangerous, but don't deal with coding or s3 on a daily basis. There seems to be an assumption in a LOT of plugins that all users can quickly grasp these kinds of instructions and beep-bop-boop... it's so easy. Nothing can be further from the truth.

HOWEVER, I am a UX Designer and would be happy to help out on developing more detailed explanations and step-by-step instruction guide for people (like me) who don't know the intricacies of proper JSON syntax but can follow more detailed instructions. Let me know if you want some help on fleshing this out a bit more and making it a bit more understandable.

Thanks!

Jim

Mobile Device Support

Hello jvsteiner,

First of all, I want to express my gratitude to you for creating such an amazing plugin.

It is, as far as I can tell, the only one that even supports the installation on mobile devices (iPad Pro in my case).

However, I cant seem to get the image upload process working on mobile. I am certain that I am either doing something wrong or this feature could easily be implemented because it does actually work with the Imgur plugin that you were inspired by.

I would be extremely thankful if we could look into this issue as it would make my workflow much easier.
(As of now, I have to save the files on my server separately when I am at University and later upload them with my Windows PC and the plugin when I am at home.)

Whenever I try to paste an image into my vault right now, it simply does nothing.

I am hoping for your support and would be happy to test out different things and versions to get it working.

Security Risk with AWS Key and Secrets and Git

Hi,

For those of us who sync our repositories with Git, the addition of data.json to the .obsidian/ folder creates a security risk as the AWS KEY and AWS SECRET are stored in plaintext. Would there be a way to have the plugin refer to the system AWS credentials during plugin load?

I'm not familiar with how Plugins are loaded in Obsidian but a common way to include AWS credentials in JS is:

const AWS = require('aws-sdk');

// Create an AWS SDK client
const s3 = new AWS.S3();

// Get the AWS credentials from the environment
const credentials = new AWS.Credentials({
  accessKeyId: process.env.AWS_ACCESS_KEY_ID,
  secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
});

// Set the AWS credentials on the S3 client
s3.config.credentials = credentials;

Thanks!

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.