Skip to content

文件上传 format 第一个参数 files 为空数组 #547

Closed
@limodou

Description

@limodou

请先看《提问的智慧》,并尝试到黑客派搜寻资料解决问题。


编辑模式

请选择你遇到问题时使用的编辑模式(把正常情况模式删掉):

所见即所得模式

描述问题

在自定义后台上传返回的结果,使用 format 进行转换,但是第一个参数总是拿到空数组,原本我理解应该是原始的文件名数组。

期待的结果

期望返回原始文件名数组。

其他信息

responseText = vditor.options.upload.format(files as File [], xhr.responseText);

这里的 files 我得到是空数组

Activity

Vanessa219

Vanessa219 commented on Jul 9, 2020

@Vanessa219
Owner

你是通过拖拽、录音、点击上传按钮还是粘贴文本图片进行上传的呢?

limodou

limodou commented on Jul 9, 2020

@limodou
Author

点击上传。

Vanessa219

Vanessa219 commented on Jul 9, 2020

@Vanessa219
Owner

你这样打印了看一下输出

 format (files, responseText) {
      console.log(files, responseText)
    }
limodou

limodou commented on Jul 10, 2020

@limodou
Author

image
这里我们后台是没有返回前端的文件名的

Vanessa219

Vanessa219 commented on Jul 10, 2020

@Vanessa219
Owner

format 会将后端的 responseText 和文件一起传递给你,你转换为需要的 responseText 返回就可以了。
使用方式

new Vditor('vditor', {
upload: {
    format(files, responseText) {
      // 更改数据结构 JSON.parse(responseText);
      return JSON.stringify({
        // 要求的数据结构
      })
    },
    url: '/api/upload/editor',
}
})

源代码

if (vditor.options.upload.format) {
  responseText = vditor.options.upload.format(files as File [], xhr.responseText);
}
added this to the 3.3 milestone on Jul 10, 2020
self-assigned this
on Jul 10, 2020
limodou

limodou commented on Jul 10, 2020

@limodou
Author

我知道这个,但是 files 是空数组。我粘贴图片 files 都是有内容的,比如:

image

Vanessa219

Vanessa219 commented on Jul 10, 2020

@Vanessa219
Owner

哦。我理解错了,不好意思

added a commit that references this issue on Jul 10, 2020
0198d71

4 remaining items

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Projects

No projects

Relationships

None yet

    Development

    No branches or pull requests

      Participants

      @limodou@Vanessa219@umi-soft

      Issue actions

        文件上传 format 第一个参数 files 为空数组 · Issue #547 · Vanessa219/vditor