Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upload adapter for inlining images using base64 URLs #1378

Closed
Reinmar opened this issue Nov 28, 2018 · 7 comments · Fixed by ckeditor/ckeditor5-upload#93
Closed

Upload adapter for inlining images using base64 URLs #1378

Reinmar opened this issue Nov 28, 2018 · 7 comments · Fixed by ckeditor/ckeditor5-upload#93
Assignees
Labels
type:docs This issue reports a task related to documentation (e.g. an idea for a guide). type:feature This issue reports a feature request (an idea for a new functionality or a missing option).
Milestone

Comments

@Reinmar
Copy link
Member

Reinmar commented Nov 28, 2018

Is this a bug report or feature request? (choose one)

🆕 Feature request

📃 Other details that might be useful

It should be fairly easy (if not trivial) to write a simple upload adapter which inlines files as base64 encoded URLs.

We might either release it (even as a part of ckeditor5-upload, because it's so generic) or simply keep in the docs as a snippet. @oleq will be working on a deep dive guide on how to write custom upload adapters and this can be one of the options shown there (the other should be a normal upload adapter).

@Reinmar
Copy link
Member Author

Reinmar commented Nov 28, 2018

@f1ames will be able to help with how to write it

@Reinmar Reinmar added type:feature This issue reports a feature request (an idea for a new functionality or a missing option). status:confirmed type:docs This issue reports a task related to documentation (e.g. an idea for a guide). labels Nov 28, 2018
@Reinmar Reinmar added this to the next milestone Nov 28, 2018
@f1ames f1ames self-assigned this Nov 29, 2018
@f1ames
Copy link
Contributor

f1ames commented Nov 29, 2018

I created a snippet with Base64UploadAdapter - https://gist.github.com/f1ames/f0d154e2a1fbeefcac5bb4dff20920ec. It works the same as regular adapter and can be used instead of it, but ofc it does not upload the file but transforms it into base64 string. Tested it with our image upload editing pipeline and it works fine 👍

@Reinmar I can transform it into a plugin or add to existing one? (I think it could be useful for people without upload which still would like to preserve images).


The Base64UploadAdapter still needs a File instance to be provided to inline it into base64 string (so works fine with our image dialog or dropping images). Still if image with different type of source lands in the content (blob:, http://) it will not be handled. I was just curious if we could have something like UrlReader (which reads an URL to a File instance) which can be integrated with Base64UploadAdapter or any other upload adapter (basically with image upload pipeline). Quick PoC - https://gist.github.com/f1ames/7876b2a18d89d9eb5f9719e98dd60de3 (based ofc on our FileReader). Funny thing I have realised it could be used for a same thing which was introduced in "Support for uploading images with base64 source" PR in ckeditor5-image ckeditor/ckeditor5-image#248, but represents quite different approach (ofc needs some changes in image upload pipeline to be integrated).

@oleq
Copy link
Member

oleq commented Dec 7, 2018

TBH I'm for making it a guide section first, especially that the code is very short and I've never seen anyone requesting this kind of feature.

We could create 2 sub-sections under this one https://ckeditor5.github.io/docs/nightly/ckeditor5/latest/framework/guides/deep-dive/upload-adapter.html#implementing-a-custom-upload-adapter like "Upload to the server" (with the current one) and "Base64–encoded inline content" (with the new one).

@coslac
Copy link

coslac commented Dec 10, 2018

Hello everyone.

How do I set up this upload adapter for inlining images on my angular project? I'm using CKEditor5.

@manyaml
Copy link

manyaml commented Feb 22, 2019

is there an example to use Base64UploadAdapter or any documentation?

@f1ames
Copy link
Contributor

f1ames commented Feb 25, 2019

@manyaml see the first gist from this #1378 (comment).

@Nothing-Works
Copy link

Nothing-Works commented May 20, 2019

@f1ames hi thank you for sharing the gist from #1378(comment)
just one thing I noticed that when I tried it out, this.loader.file is not File, it's Promise.

I can not put it in reader.readAsDataURL() .

And I do not think we can use async and await because of the UploadAdapter interface .

so I have to do something like this

this.loader.file.then( file => new Promise( (resolve, reject)=>{
       .................................................................................
             reader.readAsDataURL( file );
} ) )

correct me if I am wrong, or did I miss something?

@Reinmar Reinmar assigned pomek and unassigned f1ames May 29, 2019
oleq added a commit to ckeditor/ckeditor5-upload that referenced this issue Jun 25, 2019
Feature: Introduced the Base64 image upload adapter. Closes ckeditor/ckeditor5#1378.
oleq added a commit that referenced this issue Jun 25, 2019
Docs: Added a short note about the Base64 image upload adapter in the "Image upload overview" guide (see #1378).
@mlewand mlewand modified the milestones: next, iteration 25 Jun 26, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:docs This issue reports a task related to documentation (e.g. an idea for a guide). type:feature This issue reports a feature request (an idea for a new functionality or a missing option).
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants