add two inputs for posts and comments
This commit is contained in:
@@ -1,29 +1,42 @@
|
|||||||
import { useState } from 'react'
|
|
||||||
import axios from 'axios'
|
import axios from 'axios'
|
||||||
import './App.css'
|
import './App.css'
|
||||||
|
|
||||||
function App() {
|
function App() {
|
||||||
|
let postFile: File | undefined
|
||||||
|
let commentFile: File | undefined
|
||||||
|
|
||||||
const uploadPosts = async (file: React.ChangeEvent<HTMLInputElement>) => {
|
const uploadFiles = async () => {
|
||||||
if (file.target.files) {
|
if (!postFile || !commentFile) {
|
||||||
const formData = new FormData()
|
alert('Please select both files before uploading.')
|
||||||
formData.append('file', file.target.files[0])
|
return
|
||||||
try {
|
}
|
||||||
const response = await axios.post('http://localhost:5000/upload_posts', formData, {
|
|
||||||
headers: {
|
const formData = new FormData()
|
||||||
'Content-Type': 'multipart/form-data'
|
formData.append('posts', postFile)
|
||||||
}
|
formData.append('comments', commentFile)
|
||||||
})
|
|
||||||
console.log('File uploaded successfully:', response.data)
|
try {
|
||||||
} catch (error) {
|
const response = await axios.post('http://localhost:5000/upload', formData, {
|
||||||
console.error('Error uploading file:', error)
|
headers: {
|
||||||
}
|
'Content-Type': 'multipart/form-data',
|
||||||
|
},
|
||||||
|
})
|
||||||
|
console.log('Files uploaded successfully:', response.data)
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error uploading files:', error)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<input type="file" onChange={uploadPosts} />
|
<div className="post-file-upload">
|
||||||
|
<h2>Posts File</h2>
|
||||||
|
<input type="file" onChange={(e) => postFile = e.target.files?.[0]}></input>
|
||||||
|
</div>
|
||||||
|
<div className="comment-file-upload">
|
||||||
|
<h2>Comments File</h2>
|
||||||
|
<input type="file" onChange={(e) => commentFile = e.target.files?.[0]}></input>
|
||||||
|
</div>
|
||||||
|
<button onClick={uploadFiles}>Upload</button>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user