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.handler() #469

Closed
TobiasTao opened this issue Jun 1, 2020 · 10 comments
Closed
Assignees

Comments

@TobiasTao
Copy link
Contributor

你在什么场景下需要该功能?

自定义upload逻辑:

 upload: {
      accept: 'image/*',
      handler(files) {
        handleImg(files);
      }
    },

现在,如果复制网页中的图片:
image
将其粘贴,那么这个路径是图片源连接:
image
自定义的handler() 未生效,希望粘贴网页图片时可以触发 upload.handler()

@TobiasTao
Copy link
Contributor Author

粘贴本地图片时也无法触发 upload.handler()

@TobiasTao TobiasTao changed the title 希望粘贴网页图片时可以触发 upload.handler() 希望粘贴网页(本地)图片时可以触发 upload.handler() Jun 1, 2020
@TobiasTao TobiasTao changed the title 希望粘贴网页(本地)图片时可以触发 upload.handler() 希望粘贴网页、本地图片时可以触发 upload.handler() Jun 1, 2020
@TobiasTao TobiasTao changed the title 希望粘贴网页、本地图片时可以触发 upload.handler() 希望粘贴网页图片、本地图片时可以触发 upload.handler() Jun 1, 2020
@Vanessa219
Copy link
Owner

粘贴的时候可以使用 linkToImgUrl

@TobiasTao
Copy link
Contributor Author

我在写一个vscode插件,想用vditor替代内置的markdown编辑器。
https://github.com/TobiasTao/vscode-md
我现在的想法是拖拽(已实现)、剪切板粘贴的图片都可以通过 upload.handler() 拦截下来,进行自定义处理,例如写入本地,上传到图床等。
用 linkToImgUrl 好像无法完成

@jakekwak
Copy link
Contributor

jakekwak commented Jun 2, 2020

This idea is for mobile. At the mobile, everybody is not typing. they just copy & paste.
If it is useful, I will PR. I think @Vanessa219 will upgrade my code.

vditor66

TobiasTao pushed a commit to TobiasTao/vscode-md that referenced this issue Jun 2, 2020
Currently only drag and drop image upload is supported. After Vanessa219/vditor#469  is resolved, support paste the picture onto the clipboard and upload it.
@Vanessa219
Copy link
Owner

In SV mode, should be wait #355 & #354

@Vanessa219
Copy link
Owner

This idea is for mobile. At the mobile, everybody is not typing. they just copy & paste.
If it is useful, I will PR. I think @Vanessa219 will upgrade my code.

vditor66

I think @TobiasTao wants to listen to the paste event and trigger upload.handler, what you want to PR is to paste the URL and convert it to an image?

@jakekwak
Copy link
Contributor

jakekwak commented Jun 4, 2020

I don't know what @TobiasTao exactly want , but I think he want upload.handler to make markdown image text when he copy & paste the image.
If it is correct, this one is much better than 'upload.handler`.

@TobiasTao
Copy link
Contributor Author

I want: fromhandler(files: File[]) to handler(files: File[] | string)
if drag and drop images, I can get File[] in handler, if paste a image from clipboard, I can get string in handler, which is image's path.

@Vanessa219
Copy link
Owner

handler 和 linkToImgUrl 的参数和返回值不一致,因此新加了一个 options.upload.linkToImgCallback

#614

@aircjm
Copy link

aircjm commented Nov 24, 2020

你好 我试了下粘贴剪贴板的图片

image
这种方式是可以触发上传,调用后端接口的

但是我想要自定义上传带其他参数 所以想要使用axios调用的方式上传 但是只有上传本地文件是可以进入的
image

粘贴剪贴板图片(不是图片地址)是截图
是无法进handler的 这个有什么办法进去吗??

        upload: {
          filename (name) {
            return name.replace(/\?|\\|\/|:|\||<|>|\*|\[|\]|\s+/g, '-')
          },
          handler (files) {
            debugger
            console.log(files)
            for (let i = 0; i < files.length; i++) {
              that.uploadFiles(files[i])
                .then({})
                .catch(e => {
                  console.log(e)
                })
            }
          },
          linkToImgUrl (files) {
            debugger
          }
        }

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

No branches or pull requests

4 participants