Javascript 从服务器返回图像后重新加载奇怪的页面
我使用React在文件输入中选择一些文件,并将它们作为缓冲区发送到nodejs服务器。在服务器上,我调整大小,保存图像并将生成的链接发送到客户端 客户端得到了链接并奇怪地重新加载页面,问题是为什么 反应类零件:Javascript 从服务器返回图像后重新加载奇怪的页面,javascript,html,node.js,reactjs,Javascript,Html,Node.js,Reactjs,我使用React在文件输入中选择一些文件,并将它们作为缓冲区发送到nodejs服务器。在服务器上,我调整大小,保存图像并将生成的链接发送到客户端 客户端得到了链接并奇怪地重新加载页面,问题是为什么 反应类零件: handleClick() { const {send, value} = this.props const {attachments} = this.state if (attachments.length) { send(value, att
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)
}
有趣的提示:将图像大小调整为小尺寸(如100x100)可以解决这个问题
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)
})
})