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

Question: upload image to server at drag/drop #349

Closed
MRB60 opened this issue Apr 25, 2020 · 5 comments
Closed

Question: upload image to server at drag/drop #349

MRB60 opened this issue Apr 25, 2020 · 5 comments

Comments

@MRB60
Copy link

MRB60 commented Apr 25, 2020

Again, thanks for your great work here!
When an image is dragged and dropped into editor window, it always get inline base64 encoded. I need to have it sent to server instead (contents gets too large with base64).
It works fine with the image plugin, but not at drag/drop. Do you have any guideline on how I can achieve this also for images inserted with drag/drop?
onImageUpload() gets called but e.g. not onImageUploadBefore(). I set imageUploadUrl but see nothing sent to server at drag/drop.

@JiHong88 JiHong88 added the bug label Apr 27, 2020
@JiHong88 JiHong88 added this to the 2.29.0 milestone Apr 27, 2020
@JiHong88
Copy link
Owner

JiHong88 commented May 1, 2020

Hi,
The issue is not reproduced.
Image drop and dialog popup action are call same methods.
Are the plugin and drag/drop behavior different in the same editor?

@JiHong88 JiHong88 added question and removed bug labels May 1, 2020
@JiHong88 JiHong88 removed this from the 2.29.0 milestone May 1, 2020
@MRB60
Copy link
Author

MRB60 commented May 1, 2020

Update:
I am on a Linux Mint laptop.
I did a mistake and did a drag/drop on images in Google Search images result - these thumbs are themselves base64 encoded - so no surprise they get base64 encoded in Suneditor.
I prohibit copy/paste by using onPaste(). Drag/drop however causes no onPaste() event, instead onDrop() and onImageUpload() are called. Is there a possibility to check contents somewhere and return false to prohibit "drop"?
Otherwise, Suneditor either uploads images (e.g. drag/drop via file manager) or link the url if drag/drop, copy/paste on most web pages. All fine.

@JiHong88 JiHong88 added this to the 2.29.0 milestone May 4, 2020
@JiHong88
Copy link
Owner

JiHong88 commented May 4, 2020

I'll adjust the timing the "onDrop" user event to called before excuting the editor action.
You can use it like the current "onPaste" event.

JiHong88 added a commit that referenced this issue May 4, 2020
@JiHong88 JiHong88 closed this as completed May 4, 2020
@MRB60
Copy link
Author

MRB60 commented May 4, 2020

Thanks!
Here is an example how a drop event (here only string: text/html) can be checked to prohibit base64 encoded drop in onDrop():

for (let i = 0; i < ev.dataTransfer.items.length; i++) {
   if (ev.dataTransfer.items[i].kind === 'string' && ev.dataTransfer.items[i].type === 'text/html') {
      ev.dataTransfer.items[i].getAsString(function (s) {
         if (s.includes('<img') && s.includes('base64')) {
            alert ("Error: image type not supported");
            return false;
         } else if (s.length > 2047) {
            alert ("Error: Drop element too large");
            return false;
         }
      });
   }
}
return true;

@JiHong88
Copy link
Owner

JiHong88 commented May 8, 2020

The 2.29.0 version has been updated.
If this issue has not been resolved, please reopen this issue.
Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants