implemented file upload
This commit is contained in:
parent
713a96efc5
commit
318343e731
@ -1,5 +1,6 @@
|
|||||||
import React from "react"
|
import React from "react"
|
||||||
import { useState } from "react"
|
import { useState } from "react"
|
||||||
|
import uploadFile from "../functions/uploadFile"
|
||||||
import { useOpenDirQuery } from "../generated/graphql"
|
import { useOpenDirQuery } from "../generated/graphql"
|
||||||
import Breadcrum from "./Breadcrum"
|
import Breadcrum from "./Breadcrum"
|
||||||
import DragAndDrop from "./DragAndDrop"
|
import DragAndDrop from "./DragAndDrop"
|
||||||
@ -17,17 +18,22 @@ const FileBrowser: React.FC = () => {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
function handleDrop(files:FileList) {
|
async function handleDrop(files:FileList) {
|
||||||
|
const wait: Promise<boolean>[] = []
|
||||||
for (let i = 0; i < files.length; i++) {
|
for (let i = 0; i < files.length; i++) {
|
||||||
const file = files[i]
|
const file = files[i]
|
||||||
console.debug(file) // TODO
|
wait.push(uploadFile(file, path + file.name))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
await Promise.all(wait)
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<DragAndDrop
|
<DragAndDrop
|
||||||
handleDrop={handleDrop}
|
handleDrop={async (files)=>{
|
||||||
|
await handleDrop(files)
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
<Breadcrum path={path} onDirClick={(newPath)=>{
|
<Breadcrum path={path} onDirClick={(newPath)=>{
|
||||||
setPath(newPath)
|
setPath(newPath)
|
||||||
|
17
src/functions/uploadFile.ts
Normal file
17
src/functions/uploadFile.ts
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
async function uploadFile(file:File,id: string): Promise<boolean> {
|
||||||
|
|
||||||
|
console.debug(file)
|
||||||
|
|
||||||
|
|
||||||
|
const res = await fetch(`/api/file?${new URLSearchParams({id:id}).toString()}`,{
|
||||||
|
method: "POST",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": file.type
|
||||||
|
},
|
||||||
|
body: file
|
||||||
|
})
|
||||||
|
|
||||||
|
return res.status == 200
|
||||||
|
}
|
||||||
|
|
||||||
|
export default uploadFile
|
Loading…
Reference in New Issue
Block a user