Flask:获取从 Postman 发送的 gzip 文件名 [英] Flask: Get gzip filename sent from Postman
问题描述
I am sending a gzip file from Postman to a Flask endpoint. I can take that binary file with request.data
and read it, save it, upload it, etc.
My problem is that I can't take its name. How can I do that?
My gzip file is called "test_file.json.gz" and my file is called "test_file.json".
How can I take any of those names?
Edit:
I'm taking the stream data with io.BytesIO(), but this library doesn't contain a name attribute or something, although I can see the file name into the string if I just:
>>>print(request.data)
>>>b'x1fx8bx08x08xcaxb1xd3]x00x03test_file.jsonx00xabxe6RPPxcaNxad4Txb2RP*Kxcc)M5Txe2xaax05x00xc2x8bxb6;x16x00x00x00'
Further to the comment, I think the code which handles your upload is relevant here.
See this answer regarding request.data
:
request.data
Contains the incoming request data as string in case it came with a mimetype Flask does not handle.
The recommended way to handle file uploads in flask is to use:
file = request.files['file']
file
is then of type:werkzeug.datastructures.FileStorage
.file.stream
is the stream, which can be read withfile.stream.read()
or simplyfile.read()
file.filename
is the filename as specified on the client.file.save(path)
a method which saves the file to disk.path
should be a string like'/some/location/file.ext'
这篇关于Flask:获取从 Postman 发送的 gzip 文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!