简体   繁体   中英

Blueimp multiple chunk upload with form data

I want to chunk upload multiple files with form data. Save form data to database and image to a perticualr folder.

I'm using blueimp upload here is my Fiddle .

The JavaScript codde i'm using

$(function () {
    $('#fileupload').fileupload({
        maxChunkSize: 5000,
        previewMaxHeight: 210,
        previewMaxWidth: 210,
        url: '/echo/json'
    });
    $('#fileupload').bind('fileuploadsubmit', function (e, data) {
        var inputs = data.context.find(':input');
        if (inputs.filter('[required][value=""]').first().focus().length) {
            return false;
        }
        data.formData = inputs.serializeArray();
    });
});

Chunk upload is working fine, but if I save data to database multiple entries are created. The number of entries created in database is equal to number chunk uploaded.

在此处输入图片说明

The PHP code that i'm using is ( taking help of blueimp PHP class https://github.com/blueimp/jQuery-File-Upload/blob/master/server/php/UploadHandler.php )

public function postUpload()
{
    $upload_handler = new UploadHandler(); // Blueimp class

    $this->file->create(Input::all()); // This code is executed multiple times

}

So main trouble is $this->file->create(Input::all()); code is execute multiple times as the number of chunks uploaded, where as I want it to be executed once when file is uploaded successfully.

Also want to name file of the file that is uploaded to save it to database.

You need to first upload all the chunks and on the last chunk execute your own logic. So here is how you can do this.

You should first extract the range info from http header Content-Range . You can look at this answer for how to. Then you should check if that's the last chunk.

And if it is the last chunk you simly execute your business logic there.

Even if it is a late answer, it might help someone.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM