import express from 'express'
import multer from 'multer'
import { uploadFromBuffer } from '../utils/uploadFromBuffer'
const storage = multer.memoryStorage()
const upload = multer({
storage: storage,
limits: {
fileSize: 1024 * 1024,
},
}).array('images', 4)
class UploadFileController {
async uploads(req: express.Request, res: express.Response): Promise<void> {
upload(req, res, (err: any) => {
if (err) return res.send({ error: 'invalid_file' })
console.log('hello from here')
const files: any = req.files
const urls = []
for (const file of files) {
const result = await uploadFromBuffer(file.buffer, 'Tweets')
urls.push(result)
}
res.status(200).json({
message: 'images uploaded successfully',
data: urls,
})
})
}
}
export const UploadFileCtrl = new UploadFileController()
const [images, setImages] = React.useState<ImageObj[]>([])
const onSelectImage = React.useCallback((e: React.ChangeEvent<HTMLInputElement>) => {
const files = e.target.files
if (files) {
const imgArray: Array<File> = Array.from(files)
const newState = imgArray.map((file: File) => ({
blobUrl: URL.createObjectURL(new Blob([file])),
file,
}))
// setImages((prev: ImageObj[]): Array<ImageObj> => [...prev, ...newState])
setImages((prev: ImageObj[]): any => {
if (prev.length + imgArray.length <= 4) {
return [...prev, ...newState]
} else {
enqueueSnackbar('Max 4 photos.', {
variant: 'info',
})
}
})
}
}, [])
{Object.keys(profile.contacts).map((key) => {
return (
<React.Fragment>
<TextField
key={key}
className={classes.gutters}
margin='dense'
fullWidth
variant='outlined'
id='standard-basic'
name={`contacts.${key}`}
label={key}
value={values.contacts[key]}
onBlur={handleBlur}
onChange={handleChange}
error={touched.contacts?.[key] && Boolean(errors.contacts?.[key])}
helperText={touched.contacts?.[key] && errors.contacts?.[key]}
/>
</React.Fragment>
)
})}
const Post: React.FC<PropsType> = ({ text, smallPhoto, date }) => {
const classes = useStyles()
return (
<Paper className={classes.post}>
<Grid container alignItems={'center'}>
<Avatar className={classes.avatar} src={smallPhoto} alt='' />
<Grid item justify={'center'}>
<Typography variant={'subtitle1'}>{text}</Typography>
{date}
</Grid>
</Grid>
</Paper>
)
}
new Date().toLocaleString()
внутри самого поста но при добавлении постов дата меняется у всех на текущую