Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/rust/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 从服务器返回图像后重新加载奇怪的页面_Javascript_Html_Node.js_Reactjs - Fatal编程技术网

Javascript 从服务器返回图像后重新加载奇怪的页面

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

我使用React在文件输入中选择一些文件,并将它们作为缓冲区发送到nodejs服务器。在服务器上,我调整大小,保存图像并将生成的链接发送到客户端

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

反应类零件:

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)
        })
})