MCPcopy Create free account
hub / github.com/FlowiseAI/Flowise / handleFileUpload

Function handleFileUpload

packages/ui/src/ui-component/file/File.jsx:13–55  ·  view source on GitHub ↗
(e)

Source from the content-addressed store, hash-verified

11 const [myValue, setMyValue] = useState(value ?? '')
12
13 const handleFileUpload = async (e) => {
14 if (!e.target.files) return
15
16 if (e.target.files.length === 1) {
17 const file = e.target.files[0]
18 const { name } = file
19
20 const reader = new FileReader()
21 reader.onload = (evt) => {
22 if (!evt?.target?.result) {
23 return
24 }
25 const { result } = evt.target
26
27 const value = result + `,filename:${name}`
28
29 setMyValue(value)
30 onChange(value)
31 }
32 reader.readAsDataURL(file)
33 } else if (e.target.files.length > 0) {
34 let files = Array.from(e.target.files).map((file) => {
35 const reader = new FileReader()
36 const { name } = file
37
38 return new Promise((resolve) => {
39 reader.onload = (evt) => {
40 if (!evt?.target?.result) {
41 return
42 }
43 const { result } = evt.target
44 const value = result + `,filename:${name}`
45 resolve(value)
46 }
47 reader.readAsDataURL(file)
48 })
49 })
50
51 const res = await Promise.all(files)
52 setMyValue(JSON.stringify(res))
53 onChange(JSON.stringify(res))
54 }
55 }
56
57 const handleFormDataUpload = async (e) => {
58 if (!e.target.files) return

Callers 1

FileFunction · 0.70

Calls 2

stringifyMethod · 0.80
onChangeFunction · 0.50

Tested by

no test coverage detected