python 服务器的最佳解决方案文件上传是什么

What is best solution file upload for python server

我编程 python 服务器和 android 客户端。 程序的逻辑是客户端向服务器发送多个文件。
我首先尝试 C/C++ 套接字服务器但收到错误。所以我改变了python。因为服务器在 raspberry pi.
我必须实现文件上传、音频流。所以我觉得这个逻辑。

1.客户端向服务器发送http请求
2.当服务器收到请求时,服务器创建tcp套接字并监听。
3.客户端收到成功响应,连接到服务器并上传文件。

音频流将以类似的方式实现。

这样实现可以吗?或者,还有更好的方法?
请给我提示如何实现它。

对于小型部署,尽可能多地忽略套接字。它们处理起来稍微复杂一些。

现在假设您想将图像文件或其他文件上传到 python,您可以使用 Flask Upload

接下来转到音频,如果您必须将音频从客户端上传到服务器,则无需流式传输或其他内容,只需在上传过程中传递适当的 MIME 类型即可。

ALLOWED_AUDIO_EXTENSIONS = set(['wav', 'ogg', 'mp3', ])

def audio_file(filename):
    return '.' in filename and \
           filename.rsplit('.', 1)[1].lower() in ALLOWED_AUDIO_EXTENSIONS

if file and audio_file(file.filename):
    filename = secure_filename(file.filename)
    #perform some application logic with audio files and then save them in file system or call boto3 to save on s3

    file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
    return redirect(url_for('uploaded_file',
                                    filename=filename))

代码修改自烧瓶示例。