Copy import React from "react"
import { selectFile } from "@corets/input-helpers"
import axios from "axios"
const Example = () => {
const handleSelectFile = async () => {
const file = await selectFile ()
if ( ! file) return
submitFile (file)
}
const submitFile = async (file : File ) => {
const formData = new FormData ()
formData .append ( 'file' , file)
await axios .post ( `/endpoint` , formData , {
headers : { 'content-type' : 'multipart/form-data' } ,
})
}
return < button onClick = {handleSelectFile}/>
}
Copy import React , { useState } from "react"
import { selectFileOfType } from "@corets/input-helpers"
const Example = () => {
const [ selectedFile , setSelectedFile ] = useState ()
const handleSelectFileOfType = async () => {
const file = await selectFileOfType ( 'image/*' )
if ( ! file) return
setSelectedFile (file)
}
return (
< div >
< button onClick = {handleSelectFileOfType} />
{selectedFile && (
<img src = {URL.createObjectURL(selectedFile)} />
)}
</ div >
)
}
Copy import { selectFile } from "./selectFile"
const file = await selectFile ()
if (file) {
// some something with the file...
}
Copy import { selectFiles } from "@corets/input-helpers"
const files = await selectFiles ()
if ( files . length > 0 ) {
// do something with the files...
}
Copy import { selectFileOfType } from "@corets/input-helpers"
const file = await selectFileOfType ( 'image/*' )
if (file) {
// so something with the file
}
Copy import { selectFilesOfType } from "@corets/input-helpers"
const files = await selectFilesOfType ( 'image/*' )
if ( files . length > 0 ) {
// so something with the files...
}