Skip to content

Success Event Response Text Empty... #11

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
dainemedia opened this issue Jun 3, 2018 · 4 comments
Closed

Success Event Response Text Empty... #11

dainemedia opened this issue Jun 3, 2018 · 4 comments

Comments

@dainemedia
Copy link

Hey,

Whenever I hook into the success event, the response is always empty.

this.$refs.sectionDropzone[0].dropzone.on('success', (file, responseText) => {
    console.log(file, responseText);

    if (responseText) {
        this.getTicket()
            .then(ticket => {
                this.ticket = ticket;

                this.setProgressMeter();
                this.checkProgress(file);
                this.uploadVideo(file, responseText);
            });
    }
});

Here's my PHP code:

<?php

namespace App\Http\Controllers\API;

use Storage;
use App\Models\Video;
use Illuminate\Http\Request;
use Illuminate\Http\UploadedFile;
use App\Http\Controllers\Controller;
use App\Models\CourseChapterSection as Section;
use Pion\Laravel\ChunkUpload\Exceptions\UploadMissingFileException;
use Pion\Laravel\ChunkUpload\Handler\AbstractHandler;
use Pion\Laravel\ChunkUpload\Handler\HandlerFactory;
use Pion\Laravel\ChunkUpload\Receiver\FileReceiver;

class SectionVideoController extends Controller
{
    protected $section;
    protected $video;

    public function __construct(Section $section, Video $video)
    {
        $this->section = $section;
        $this->video = $video;
    }

    public function index()
    {
        $section = $this->section->find(request()->section_id);

        return $section->videos;
    }

    /**
     * Handles the file upload
     *
     * @param Request $request
     *
     * @return \Illuminate\Http\JsonResponse
     *
     * @throws UploadMissingFileException
     * @throws \Pion\Laravel\ChunkUpload\Exceptions\UploadFailedException
     */
    public function store(Request $request) {
        // create the file receiver
        $receiver = new FileReceiver('video', $request, HandlerFactory::classFromRequest($request));

        // check if the upload is success, throw exception or return response you need
        if ($receiver->isUploaded() === false) {
            throw new UploadMissingFileException();
        }

        // receive the file
        $save = $receiver->receive();

        // check if the upload has finished (in chunk mode it will send smaller files)
        if ($save->isFinished()) {
            $file = $save->getFile();

            // save the file and return any response you need, current example uses `move` function. If you are
            // not using move, you need to manually delete the file by unlink($save->getFile()->getPathname())
            $filename = str_slug(basename(time(), '.'.$file->getClientOriginalExtension())).'.'.$file->getClientOriginalExtension();;
        
            // move the file name
            $file->move(storage_path().'/app/media/video/', $filename);

            return storage_path().'/app/media/video/'.$filename;
        }

        // we are in chunk mode, lets send the current progress
        /** @var AbstractHandler $handler */
        $handler = $save->handler();

        return response()->json([
            'done' => $handler->getPercentageDone(),
            'status' => true
        ]);
    }

    public function destroy($id)
    {
        $video = $this->video->find($id);
        $video->sections()->detach(request()->section_id);
        $video->delete();
    }
}

No matter what I do, I cannot get the response after successfully uploading all chunks.

The success event is fired and a can log the file paramter, but the responseText argument is always empty.

Any ideas?

@pionl
Copy link
Owner

pionl commented Sep 10, 2018

Hi, we have already discussed it, it seems to be drozpzone issue: pionl/laravel-chunk-upload#41

@eliasdiek
Copy link

Hi,
How are you?
Thanks for your example :)
It's many helpful for me.
But I am facing a problem.
That is not to get the real extension of uploaded file.

This is your code.

    protected function createFilename(UploadedFile $file)
    {
        $extension = $file->getClientOriginalExtension();
        $filename = str_replace(".".$extension, "", $file->getClientOriginalName()); // Filename without extension
        // Add timestamp hash to name of the file
        $filename .= "_" . md5(time()) . "." . $extension;
        return $filename;
    }

This is some of error codes.

Symfony\Component\HttpFoundation\File\Exception\FileException: Could not move the file &quot;D:\www\csv_upload\storage\app\chunks/./blob-5d603a175d092e872ef1ba4d054994d1.part&quot; to &quot;D:\www\csv_upload\storage\app/upload\blob_007c5fee6abd9db5e02d0a10b3e18336.&quot; (rename(D:\www\csv_upload\storage\app\chunks/./blob-5d603a175d092e872ef1ba4d054994d1.part,D:\www\csv_upload\storage\app/upload\blob_007c5fee6abd9db5e02d0a10b3e18336.): Access is denied. (code: 5)) in file D:\www\csv_upload\vendor\symfony\http-foundation\File\File.php on line 100
Stack trace:
  1. Symfony\Component\HttpFoundation\File\Exception\FileException-&gt;() D:\www\csv_upload\vendor\symfony\http-foundation\File\File.php:100
  2. Symfony\Component\HttpFoundation\File\File-&gt;move() D:\www\csv_upload\vendor\symfony\http-foundation\File\UploadedFile.php:205
  3. Symfony\Component\HttpFoundation\File\UploadedFile-&gt;move() D:\www\csv_upload\app\Http\Controllers\UploadController.php:100
  4. App\Http\Controllers\UploadController-&gt;saveFile() D:\www\csv_upload\app\Http\Controllers\FileController.php:40
  5. App\Http\Controllers\FileController-&gt;fileUploadPost() D:\www\csv_upload\vendor\laravel\framework\src\Illuminate\Routing\Controller.php:54
  6. call_user_func_array() D:\www\csv_upload\vendor\laravel\framework\src\Illuminate\Routing\Controller.php:54
  7. Illuminate\Routing\Controller-&gt;callAction() D:\www\csv_upload\vendor\laravel\framework\src\Illuminate\Routing\ControllerDispatcher.php:45
  8. Illuminate\Routing\ControllerDispatcher-&gt;dispatch() D:\www\csv_upload\vendor\laravel\framework\src\Illuminate\Routing\Route.php:219
  9. Illuminate\Routing\Route-&gt;runController() D:\www\csv_upload\vendor\laravel\framework\src\Illuminate\Routing\Route.php:176
 10. Illuminate\Routing\Route-&gt;run() D:\www\csv_upload\vendor\laravel\framework\src\Illuminate\Routing\Router.php:680
......................

If I try to run after change " $extension = $file->getClient OriginalExtension() " to " $extension = $file->getExtension() or "$extension = 'zip(for example...)', it works.
But in the first case, it gets the chunked file extension. (for example .part ).

Please help me.
Thanks. :)

@pionl
Copy link
Owner

pionl commented Jun 12, 2020

Sorry I have very limited time to help you, but if you get .part then you need to make sure are use the extension when $save->isFinished() is true.

@pionl
Copy link
Owner

pionl commented Jun 21, 2020

@pionl pionl closed this as completed Jun 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants