分块文件上传有不同的文件 size/corrupt

Chunked File Uploads have different file size/corrupt

我在服务器端使用 jquery-file-upload 和 Python-Flask。每当我上传超过 100mb 的大文件时,上传的版本比原始版本 稍大并且无法打开(已损坏)。我为 10mb 块的大文件启用了分块,我尝试将 "disableImageResize" 设置为 "true" 以及尝试单个和多个文件,结果是相同的。我的代码中是否遗漏了什么?

main.js

$(function () {
'use strict';
// Initialize the jQuery File Upload widget:
$('#fileupload').fileupload({
    // Uncomment the following to send cross-domain cookies:
    //xhrFields: {withCredentials: true},
    url: 'rs_upload',
    disableImageResize: true,
    sequentialUploads: true,
   // redirect: 'home',
    done: function (e, data) {
        console.log("uploaded: " + data.files[0].name)

    }
    , maxChunkSize: 10000000, // 10 MB,
}).bind('fileuploadstop', function (e, data) {
    if (data.loaded == data.total){window.location.replace("rs_create")}
});

views.py

@app.route("/rs_upload", methods=["GET", "POST"])
def rs_upload():
if request.method == 'POST':
    files = request.files['file']
    fs = files
    handle_file(fs)
    fullpath = session.get('finalpath')
    if 'Content-Range' in request.headers:
        # extract starting byte from Content-Range header string
        range_str = request.headers['Content-Range']
        start_bytes = int(range_str.split(' ')[1].split('-')[0])

        # append chunk to the file on disk, or create new
        with open(fullpath, 'a') as f:
            f.seek(start_bytes)
            f.write(fs.stream.read())

    else:
        # this is not a chunked request, so just save the whole file
        fs.save(fullpath)

    return jsonify({"name": fs.filename,
                    "size": os.path.getsize(fullpath),
                    "url": 'uploads/' + fs.filename,
                    "thumbnail_url": None,
                    "delete_url": None,
                    "delete_type": None,})

return render_template('remote_sensing/upload.html')

不确定这是否是问题所在,但会尝试

with open(fullpath, 'ab') as f:

以二进制模式打开并附加到文件。