kopia lustrzana https://github.com/cirospaciari/socketify.py
fix formdata helper example
rodzic
cc10a3e4ba
commit
a340dda35b
|
@ -1,47 +0,0 @@
|
|||
from socketify import App
|
||||
from streaming_form_data import StreamingFormDataParser
|
||||
from streaming_form_data.targets import ValueTarget, FileTarget
|
||||
app = App()
|
||||
router = app.router()
|
||||
|
||||
@router.post("/")
|
||||
async def upload(res, req):
|
||||
print(f"Posted to {req.get_url()}")
|
||||
parser = StreamingFormDataParser(headers=req.get_headers())
|
||||
name = ValueTarget()
|
||||
parser.register('name', name)
|
||||
file = FileTarget('/tmp/file')
|
||||
file2 = FileTarget('/tmp/file2')
|
||||
parser.register('file', file)
|
||||
parser.register('file2', file2)
|
||||
|
||||
|
||||
def on_data(res, chunk, is_end):
|
||||
parser.data_received(chunk)
|
||||
if is_end:
|
||||
res.cork(on_finish)
|
||||
|
||||
|
||||
def on_finish(res):
|
||||
print(name.value)
|
||||
|
||||
print(file.multipart_filename)
|
||||
print(file.multipart_content_type)
|
||||
|
||||
print(file2.multipart_filename)
|
||||
print(file2.multipart_content_type)
|
||||
|
||||
res.end("Thanks for the data!")
|
||||
|
||||
res.on_data(on_data)
|
||||
|
||||
|
||||
@router.any("*")
|
||||
def not_found(res, _):
|
||||
res.write_status(404).end("Not Found")
|
||||
|
||||
app.listen(
|
||||
3000,
|
||||
lambda config: print("Listening on port http://localhost:%d now\n" % config.port),
|
||||
)
|
||||
app.run()
|
|
@ -117,7 +117,7 @@ async def upload_formhelper(res, req):
|
|||
# using streaming_form_data package for parsing + helper
|
||||
from streaming_form_data import StreamingFormDataParser
|
||||
from streaming_form_data.targets import ValueTarget, FileTarget
|
||||
from .helpers.form_data import get_formdata
|
||||
from helpers.form_data import get_formdata
|
||||
|
||||
|
||||
print(f"Posted to {req.get_url()}")
|
||||
|
@ -150,7 +150,7 @@ app.post("/text", upload_text)
|
|||
app.post("/urlencoded", upload_urlencoded)
|
||||
app.post("/multiple", upload_multiple)
|
||||
app.post("/formdata", upload_formdata)
|
||||
app.post("/formdata2", upload_formdata)
|
||||
app.post("/formdata2", upload_formhelper)
|
||||
|
||||
app.any("/*", lambda res, _: res.write_status(404).end("Not Found"))
|
||||
app.listen(
|
||||
|
|
Ładowanie…
Reference in New Issue