我将Flask用作移动应用程序的后端,其功能之一是上传和重命名个人资料图片的图像并发布媒体附件
最近,在开发服务器上使用它们时,上传的Web服务返回list_c = a.objects.filter(param1='a', param2='b').values_list('c', flat=True)
list_d = a.objects.filter(param1='a', param2='b').values_list('d', flat=True)
b.objects.filter(param3__in=list_c, param4__in=list_d).delete()
和FileNotFoundError: [Errno 2] No such file or directory
我真的不认为这是一个代码问题,因为它在我的本地环境下可以正常工作,但是在那儿崩溃了。
这是来自开发服务器的回溯
500 Error
这是发布功能
Traceback (most recent call last):
File "/usr/local/lib/python3.6/dist-packages/flask/app.py", line 2463, in __call__
return self.wsgi_app(environ, start_response)
File "/usr/local/lib/python3.6/dist-packages/flask/app.py", line 2449, in wsgi_app
response = self.handle_exception(e)
File "/usr/local/lib/python3.6/dist-packages/flask/app.py", line 1866, in handle_exception
reraise(exc_type, exc_value, tb)
File "/usr/local/lib/python3.6/dist-packages/flask/_compat.py", line 39, in reraise
raise value
File "/usr/local/lib/python3.6/dist-packages/flask/app.py", line 2446, in wsgi_app
response = self.full_dispatch_request()
File "/usr/local/lib/python3.6/dist-packages/flask/app.py", line 1951, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/usr/local/lib/python3.6/dist-packages/flask/app.py", line 1820, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/usr/local/lib/python3.6/dist-packages/flask/_compat.py", line 39, in reraise
raise value
File "/usr/local/lib/python3.6/dist-packages/flask/app.py", line 1949, in full_dispatch_request
rv = self.dispatch_request()
File "/usr/local/lib/python3.6/dist-packages/flask/app.py", line 1935, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "/var/www/xxxxx.com/xxxxx/controllers/posts.py", line 14, in posts
return posts_service.post(request)
File "/usr/local/lib/python3.6/dist-packages/flask_jwt/__init__.py", line 177, in decorator
return fn(*args, **kwargs)
File "/var/www/xxxxx.com/xxxxx/services/posts.py", line 82, in post
file.save(filepath)
File "/usr/local/lib/python3.6/dist-packages/werkzeug/datastructures.py", line 2800, in save
dst = open(dst, "wb")
FileNotFoundError: [Errno 2] No such file or directory: 'xxxxx/uploads/fc23dfb1-6852-47cc-9090-4aa80a1f1d9d.jpe'
我已经将上载目录更改为可由@jwt_required()
def post(request):
if 'file' not in request.files:
return {
'success': False,
'message': 'No file part in the request',
}, 200
file = request.files['file']
if file.filename == '':
return {
'success': False,
'message': 'No file selected for uploading',
}, 200
if file and allowed_file(file.mimetype):
filepath = makepath(file.mimetype)
file.save(filepath)
post = post_repo.create(
current_identity.id,
request.form['matchId'],
request.form['teamSelected'],
request.form['content'],
request.form['postType'],
filepath,
request.form['location']
)
if post:
return {
'success': True,
'message': 'Post successfully created',
'post': post_repo.to_dto(post),
}, 201
return {
'success': False,
'message': 'File extension not allowed',
}, 200
写入
dev环境使用apache 2.4和wsgi托管在docker环境中,以便为其提供服务
我应该问服务器管理员在那里签到什么?
编辑:我刚刚注意到,当我others
目录时,没有组列。难道就是为什么上传不起作用?
ls -la
更新:如注释中所建议,我尝试使用保存功能时使用绝对路径,这导致stacktrace中出现奇怪的错误消息,它生成了其他内容,例如{{ 1}},在文件夹名称前添加一个/,这很有意义,为什么在这里失败,因为该路径在服务器上不存在