2amigos / yii2-file-upload-widget

BlueImp File Upload Widget for Yii2
Other
252 stars 140 forks source link

Chunked Files #122

Open toniorocks opened 7 years ago

toniorocks commented 7 years ago

Hi amigos,

Sorry for my bad english i have an issue with the upload widget, i can´t make it work with chuncked files in Yii2, if anybody of you can point me in the right direction i'll appriciate it.

This is my code so far:

<?= FileUploadUI::widget([ 'model' => $formModel, 'attribute' => 'archivo', 'url' => ['prueba-carga/trozos'], // your url, this is just for demo purposes, 'fieldOptions' => [ 'accept' => '.pdf' ], 'clientOptions' => [ 'maxChunkSize' => 2000000, //2 mb 'maxFileSize' => 100000000 //100 mb ], // Also, you can specify jQuery-File-Upload events // see: https://github.com/blueimp/jQuery-File-Upload/wiki/Options#processing-callback-options 'clientEvents' => [ 'fileuploaddone' => 'function(e, data) { console.log(e); console.log(data); }', 'fileuploadfail' => 'function(e, data) { console.log(e); console.log(data); }', ], ]); ?>

and in the model: `public function actionTrozos() {

    // $formModel = new FormPruebaCarga();
    // $pdf = UploadedFile::getInstance($formModel, 'archivo');
    // $upload_handler = new UploadHandler();
    $formModel = new FormPruebaCarga();
    $pdf = UploadedFile::getInstance($formModel, 'archivo');
    $path = 'uploads/pruebas/';
    if ($pdf){

        $uid = uniqid(time(), true);
        $fileName = $uid . '.' . $pdf->extension;
        $filePath = $path . $fileName;
        if ($pdf->saveAs($filePath)) {
            $path_ = 'uploads/pruebas/' . $fileName;
            return Json::encode([
                'files' => [
                    [
                        'name' => $fileName,
                        'size' => $pdf->size,
                        'url' => $path_,
                        //'thumbnailUrl' => $path_,
                        'deleteUrl' => 'index.php?r=prueba-carga/elimina&name=' . $fileName,
                        'deleteType' => 'POST',
                    ],
                ],
            ]);
        }
    }

    return '';

}`

But the file is corrupted.

tonydspaniard commented 7 years ago

Hi @toniorocks thanks for using this widget. Please, check this issue regarding file uploads in chunks: https://github.com/2amigos/yii2-file-upload-widget/issues/114

Unfortunately, the action handler provider is not done for chunked files. I'll write one when I have time.