在金字塔中一次上传多个文件

时间:2014-12-03 06:53:14

标签: javascript python html sqlalchemy pyramid

我试图找到一种使用mako上传多个文件的方法,例如一次完整的mp3歌曲专辑。我现在只能上传一个。还询问我在将数据库上传到文件系统存储时如何在数据库中捕获或存储歌曲路径

if request.method == 'POST':   
    filename = request.params['mp3'].filename
    input_file = request.POST['mp3'].file

    file_path = os.path.join('/var/www/beatstore', '%s.mp3' % uuid.uuid4())

    temp_file_path = file_path + '~'
    output_file = open(temp_file_path, 'wb')

    # Finally write the data to a temporary file
    input_file.seek(0)
    while True:
        data = input_file.read(2<<16)
        if not data:
            break
        output_file.write(data)

    output_file.close()

    # Now that we know the file has been fully saved to disk move it into place.
    os.rename(temp_file_path, file_path)
    return {'project':'beatstore'}

这是我的表格:

<form enctype="multipart/form-data" action="save_file.py" method="post">
    <p>File: <input type="mp3" name="mp3"></p>
    <p><input type="submit" value="Upload"></p>
</form>

0 个答案:

没有答案