Skip to content
This repository has been archived by the owner on Jul 27, 2023. It is now read-only.

Chunked Files #122

Open
toniorocks opened this issue Sep 4, 2017 · 1 comment
Open

Chunked Files #122

toniorocks opened this issue Sep 4, 2017 · 1 comment
Labels

Comments

@toniorocks
Copy link

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
Copy link
Member

tonydspaniard commented Sep 4, 2017

Hi @toniorocks thanks for using this widget.
Please, check this issue regarding file uploads in chunks: #114

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants