从服务器获取图像后奇怪的页面重新加载

我使用React来select文件input中的一些文件,并将它们作为缓冲区发送到nodejs服务器。 在服务器上我resize,保存图像并发送生成的链接到客户端。

客户端得到的链接,奇怪的重新加载页面,问题是为什么?

React类部分:

handleClick() { const {send, value} = this.props const {attachments} = this.state if (attachments.length) { send(value, attachments) this.setState({ attachments: [] }) } } addFiles(files) { const {attachments} = this.state const newAttachments = [...attachments] Array.prototype.forEach.call(files, file => { if (newAttachments.length < 10) newAttachments.push(file) }) this.setState({ attachments: newAttachments }) } handleDrop(e) { e.preventDefault() this.addFiles(e.dataTransfer.files) } handleFilesSelect(e) { e.preventDefault() this.addFiles(e.target.files) } 

服务器代码部分:

 const saveRoomPhoto = (roomId, avatar) => new Promise((resolve, reject) => { const relativePath = `images/rooms/${roomId}/${crypto.randomBytes(5).toString('hex')}.jpg` const absolutePath = path.join(__dirname, '../../public', relativePath) gm(avatar) .resize(2048, 2048, '>') .write(absolutePath, err => { err ? reject(err) : resolve(relativePath) }) }) 

Intresting提示:将图像大小调整为小尺寸(例如100×100)可以解决问题