我一直在浏览React文件上传教程,并希望对其进行补充。我正在努力做到这一点,因此当用户单击上传消息时,浏览器将提示他们说“您的文件正在上传”,无论如何我都不是前端开发人员,因此,如果此问题是超级问题,请原谅我。由于某些原因,当我使用此代码时,如果导航到网页,则函数中的代码将运行一次,然后在单击时再次运行。我的预期用途是仅在点击时运行,知道我在做什么错吗?
import React, { Component } from 'react'
import { Alert } from 'react-alert'
class Main extends React.Component {
constructor(props) {
super(props);
this.state = {
imageURL: '',
};
this.handleUploadImage = this.handleUploadImage.bind(this);
}
handleUploadImage(ev) {
ev.preventDefault();
const data = new FormData();
data.append('file', this.uploadInput.files[0]);
data.append('filename', this.fileName.value);
fetch('http://localhost:8000/upload', {
method: 'POST',
body: data,
}).then((response) => {
response.json().then((body) => {
this.setState({ imageURL: `http://localhost:8000/${body.file}` });
});
});
}
render() {
return (
<form onSubmit={this.handleUploadImage}>
<div>
<input ref={(ref) => { this.uploadInput = ref; }} type="file" /> …Run Code Online (Sandbox Code Playgroud) 我现在在Amazon RDS设置中有一个MySQL数据库,它需要能够充当数据库并能够存储一些平面文件。
它工作了一段时间,直到我发现它没有存储超过1MB的内存...而且我不知道为什么。因此,我深入研究RDS并了解了参数组。它似乎是数据库本身配置的子集,因此我认为这是max_allowed_packet问题所在,因此将其设置为更高的值。
但是,我仍然无法上传超过1MB的内容,因此我意识到名称中还有另一个参数mysqlx_max_allowed_packet,其值设置为大约1MB,但是我无法更改它。
有谁知道如何解决这个问题,或者有可能吗?
如何在python中传递一个字符串作为参数而不包含"Namespace"的输出.
这是我的代码:
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("person", help="person to test",type=str)
person = str(parser.parse_args())
print "The person's name is " + person
Run Code Online (Sandbox Code Playgroud)
这是我正在运行的命令:
python test.py bob
Run Code Online (Sandbox Code Playgroud)
这是我的输出:
The person's name is Namespace(person='bob')
Run Code Online (Sandbox Code Playgroud)
我可能会做一些花哨的分裂,但我确定我只是错误地利用了argparse(我是python的新手),如果有人能告诉我如何正确传递这样的字符串,我会极大地贬低它.
我基本上是用一个简单的shell脚本进行测试Curl,不幸的是当我创建curl命令时,因为我以编程方式传递参数,它将我的字符串中的每个单词作为单个参数读取,并尝试将它们解析为主机,我需要按原样发送整个消息.这是代码:
Name="Bob"
LISTENER_URL='http://httpbin.org/post'
PAYLOAD="Hello my name is" $NAME
curl --request POST --url $LISTENER_URL --data $PAYLOAD --insecure
Run Code Online (Sandbox Code Playgroud)
输出将curl发送"Hello"到url,然后无法解析主机:
my
name
is
bob
Run Code Online (Sandbox Code Playgroud)
我确实尝试了以下修改,但无济于事:
curl --request POST --url $LISTENER_URL --data '"'+$PAYLOAD+'"' --insecure
curl --request POST --url $LISTENER_URL --data '"'$PAYLOAD'"' --insecure
Run Code Online (Sandbox Code Playgroud)
还尝试重新声明变量,如下所示:
PAYLOAD="\"$PAYLOAD\""
Run Code Online (Sandbox Code Playgroud)