如何从诺基亚 95 上传大文件到网络服务器?
我正在尝试使用 Pys60 python 代码将一个大文件从我的诺基亚 N95 手机上传到我的网络服务器。然而,代码崩溃了,因为我试图将文件加载到内存中并尝试发布到 HTTP url。知道如何上传大文件>使用 Pys60 到网络服务器 120 MB。
以下是我用来发送 HTTP 请求的代码。
f = open(soundpath + audio_filename)
fields = [('timestamp', str(audio_start_time)), ('test_id', str(test_id)), ('tester_name', tester_name), ('sensor_position', str(sensor_position)), ('sensor', 'audio') ]
files = [('data', audio_filename, f.read())]
post_multipart(MOBILE_CONTEXT_HOST, MOBILE_CONTEXT_SERVER_PORT, '/MobileContext/AudioServlet', fields, files)
f.close
I'm trying to upload a huge file from my Nokia N95 mobile to my webserver using Pys60 python code. However the code crashes because I'm trying to load the file into memory and trying to post to a HTTP url. Any idea how to upload huge files > 120 MB to webserver using Pys60.
Following is the code I use to send the HTTP request.
f = open(soundpath + audio_filename)
fields = [('timestamp', str(audio_start_time)), ('test_id', str(test_id)), ('tester_name', tester_name), ('sensor_position', str(sensor_position)), ('sensor', 'audio') ]
files = [('data', audio_filename, f.read())]
post_multipart(MOBILE_CONTEXT_HOST, MOBILE_CONTEXT_SERVER_PORT, '/MobileContext/AudioServlet', fields, files)
f.close
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这个
post_multipart()
函数来自哪里?如果它来自此处,那么它应该很容易调整代码,以便它在参数中接受文件对象而不是文件的完整内容,以便 post_mutipart 在发布时读取小块数据,而不是在发布之前将整个文件加载到内存中。
这绝对是可能的。
where does this
post_multipart()
function comes from ?if it is from here, then it should be easy to adapt the code so that it takes a file object in argument and not the full content of the file, so that post_mutipart reads small chunks of data while posting instead of loading the whole file in memory before posting.
this is definitely possible.
你不能。这在物理上几乎是不可能的。您需要将文件分成小块并一点一点上传,这在此类平台上很难快速有效地完成。
杰米
You can't. It's pretty much physically impossible. You'll need to split the file into small chunks and upload it bit by bit, which is very difficult to do quickly and efficiently on that sort of platform.
Jamie
您需要编写一个客户端代码,将源文件分割成小块,并在服务器端重建该块。
You'll need to craft a client code to split your source file in small chunks and rebuild that pieces server-side.