save useInputImage with correct filename

This commit is contained in:
Sanster 2022-04-14 22:22:18 +08:00
parent 78d6b1cc3e
commit 2b031603ed

View File

@ -8,14 +8,21 @@ export default function useInputImage() {
headers.append('pragma', 'no-cache') headers.append('pragma', 'no-cache')
headers.append('cache-control', 'no-cache') headers.append('cache-control', 'no-cache')
fetch('/inputimage', { headers }) fetch('/inputimage', { headers }).then(async res => {
.then(res => res.blob()) const filename = res.headers
.then(data => { .get('content-disposition')
if (data && data.type.startsWith('image')) { ?.split('filename=')[1]
const userInput = new File([data], 'inputImage') .split(';')[0]
setInputImage(userInput)
} const data = await res.blob()
}) if (data && data.type.startsWith('image')) {
const userInput = new File(
[data],
filename !== undefined ? filename : 'inputImage'
)
setInputImage(userInput)
}
})
}, [setInputImage]) }, [setInputImage])
useEffect(() => { useEffect(() => {