我正在开发一个需要上传多张图片的应用程序。我正在使用redux-saga
和Nexjs
。现在它正在上传一张图片,但选择了多张图片。
我的代码:
const inputFile = React.useRef(null);
const onChangeFile = event => {
event.stopPropagation();
event.preventDefault();
var image = event.target.files[0];
if (image) {
var temp = URL.createObjectURL(image);
onImageSelect && onImageSelect(temp);
set_disabled(true);
dispatch(
post.uploadImage({
fileObject: image,
callback: source_url => {
imageHandler(source_url);
set_disabled(false);
event.target.value = null;
onImageUploaded && onImageUploaded();
},
})
);
}
};
和JSX:
<>
<input
accept='image/*'
type='file'
ref={inputFile}
style={{ display: 'none' }}
onChange={onChangeFile}
multiple
/>
<Box clone color='#666'>
<IconButton
size='small'
onClick={() => {
inputFile.current.click();
}}
>
<WallpaperOutlinedIcon />
</IconButton>
</Box>
</>
我需要添加哪些更改才能上传多张图片,我有点搞不清楚。谢谢
2条答案
按热度按时间oyjwcjzk1#
从阵列中获取所有文件并尝试上传每个文件:
xxhby3vn2#
我没有代表直接回复你的评论,但是关于这里的另一个答案,使用Promise.all()而不是for循环。