我们正在尝试将 .mp3 文件存储在 Python 项目中。我们的前端正在使用 react 和 fetch api。我们现在正在用邮递员测试服务器。我们不断收到对邮递员的错误请求。帖子请求有问题吗?
app.config['ALLOWED_EXTENSIONS'] = ['mp3']
app.config['UPLOAD_FOLDER'] = 'static/'
def post(self):
file = request.files['file']
extension = os.path.splitext(file.filename)[1]
new_song = Song(
title=request.get_json()['title'],
likes=0,
genre=request.get_json()['genre'],
mp3=os.path.join(
app.config['UPLOAD_FOLDER'],
secure_filename(file.filename)
)
)
if file:
if extension not in app.config['ALLOWED_EXTENSIONS']:
return 'File is not an mp3.'
file.save(os.path.join(
app.config['UPLOAD_FOLDER'],
secure_filename(file.filename)
))
db.session.add(new_song)
db.session.commit()