提问人:Mehmet Emre Özer 提问时间:10/12/2023 更新时间:10/12/2023 访问量:24
如何使用 Quasar 的 q-uploader 组件将文件上传到运行 python/cgi 的服务器?
How to upload a file with Quasar's q-uploader component to a server running python/cgi?
问:
您好,我在 Windows 10 上运行 Apache2 Web 服务器,想通过 python/cgi 上传带有 Quasar 的 q-uploader 组件的单个文件?
我尝试了很多,但无法单独解决问题。
Quasar'r 网页中有一个 python/flask 的示例,但没有 python/cgi 的示例。
以下是我的代码,它没有运行:
#!/Python310/python.exe
import cgi, os
import cgitb; cgitb.enable(display=0, logdir="C:\\")
print("Content-Type: text/html")
print("Access-Control-Allow-Origin: *")
print("Access-Control-Allow-Methods: POST, GET, OPTIONS")
print("Referrer-Policy: no-referrer")
form = cgi.FieldStorage()
try:
fileitem = form['file']
except:
print("An exception occurred")
# Test if the file was uploaded
if fileitem.filename:
# strip leading path from file name
# to avoid directory traversal attacks
fn = os.path.basename(fileitem.filename)
open('uploads/' + fn, 'wb').write(fileitem.file.read())
message = 'The file "' + fn + '" was uploaded successfully'
else:
message = 'No file was uploaded'
print(message)
我预计上面的代码会从类星体前端上传,但事实并非如此。
答: 暂无答案
评论