gpt4 book ai didi

javascript - 使用 filepond 参数手动触发 filepond 中的服务器方法

转载 作者:行者123 更新时间:2023-12-02 22:09:13 25 4
gpt4 key购买 nike

我想在 filepond-react 组件中手动触发 fetch 方法。为了简化,我削减了其他 Prop 。

  // FileUpload Wrapper
<div className="file-upload">
<FilePond
ref={this.props.innerref}
files={this.state.files}
onupdatefiles={this.updateFiles}
{...this.props}
/>
</div>

  // Calling the wrapper in the parent component
<FileUpload
innerref={this.fileRef}
server={{
fetch: this.onFileFetch,
process: this.onUpload,
revert: this.onFileRevert,
}}
/>

服务器方法

// fetch
onFileFetch = async (url, load, error, progress, abort, headers) => {
// function triggers but cannot access load, progress etc. here
}

// upload
onUpload = async (fieldName, file, metadata, load, error, progress, abort) => {
// function triggers and can access load, error etc.
}

// delete/revert
onFileRevert = async (uniqueFileId, load, error) => {
// function triggers and can access load, error etc.
}

行为和触发

因此,当我分别单击上传和恢复图标时,会触发上传和删除。我想手动触发 fetch() ,为此我调用 this.fileRef.current.props.server.fetch()

为什么无法访问该函数的参数? (负载、错误等)
我在下面添加了 filepond 对象(又名 this.fileRef.current)以供引用。

```
{current: FilePond}
current: FilePond
isMounted: (...)
replaceState: (...)
props:
ref: (...)
files: []
instantUpload: false
oninit: undefined
labelIdle: "Drag file(s) here<br> or <br><br><span class="filepond--label-action">Browse</span>"
onupdatefiles: ƒ (fileItems)
innerref: {current: FilePond}
className: "in-block s3-bucket-file-input"
server:
fetch: ƒ (url, load, error, progress, abort, headers)
load: ƒ (source, load, error, progress, abort, headers)
process: ƒ (fieldName, file, metadata, load, error, progress, abort)
revert: ƒ (uniqueFileId, load, error)
restore: ƒ (uniqueFileId, load, error, progress, abort, headers)
remove: ƒ (source, load, error)
__proto__: Object
get ref: ƒ ()
__proto__: Object
context: {}
refs: {}
updater: {isMounted: ƒ, enqueueSetState: ƒ, enqueueReplaceState: ƒ, enqueueForceUpdate: ƒ}
allowFilesSync: true
_reactInternalFiber: FiberNode {tag: 1, key: null, stateNode: FilePond, elementType: ƒ, type: ƒ, …}
_reactInternalInstance: {_processChildContext: ƒ}
state: null
_element: input.in-block.s3-bucket-file-input
_pond: {on: ƒ, onOnce: ƒ, off: ƒ, setOptions: ƒ, addFile: ƒ, …}
addFile: ƒ addFile(source)
addFiles: ƒ addFiles()
getFile: ƒ getFile(query)
processFile: ƒ processFile(query)
prepareFile: ƒ prepareFile(query)
removeFile: ƒ removeFile(query)
moveFile: ƒ moveFile(query, index)
getFiles: ƒ getFiles()
processFiles: ƒ processFiles()
removeFiles: ƒ removeFiles()
prepareFiles: ƒ prepareFiles()
sort: ƒ sort(compare)
browse: ƒ browse()
__proto__: Component
__proto__: Object
```

最佳答案

如果您手动调用 this.fileRef.current.props.server.fetch(),您不会将任何参数传递给该函数。 FilePond 在调用函数时会传递这些参数 url、load、error、progress、abort、headers,因此如果您想这样使用它,您也应该这样做。

这些函数不必标记为异步,它们可以是普通函数。

关于javascript - 使用 filepond 参数手动触发 filepond 中的服务器方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59612648/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com