question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Problem with uploading files, flow-php-server and Laravel

See original GitHub issue

I ran into a problem of files not being uploaded today using flow-php-server together with Laravel. For me the problem was that the 404 header wasn’t properly returned on the test function of flow.js. Instead it would just return a 200 which in turn caused flow.js to not send the POST request after the GET request to check for the chunk existence.

In Laravel you should do something like this in the controller method that handles the flow.js requests. (taken from the basic example):

if (\Flow\Basic::save('./uploads/name_of_new_file', './chunks_temp_folder')) {
  // file saved successfully and can be accessed at './final_file_destination'
} else {
  // This is not a final chunk or request is invalid, continue to upload.
  $response = Response::make('', 404);
  return $response;
}

When I started I left the else block empty. Now the whole thing makes sense to me, but I haven’t done much backend before, so all in all this took me a couple of hours. I figured maybe posting this here helps someone else.

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Comments:11 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
AidasKcommented, Jun 28, 2014

I am not a laravel user, but the key tasks would be:

use \Flow\Request;
use \Flow\Config;
use \Flow\File;

$request = new Request();
$config = new Config(array(
   'tempDir' => 'tmp/'
));
$file = new File($config, $request);
$response = Response::make('', 200);

if ($_SERVER['REQUEST_METHOD'] === 'GET') {
    if (!$file->checkChunk()) {
        return Response::make('', 404);
    }
} else {
    if ($file->validateChunk()) {
        $file->saveChunk();
    } else {
        // error, invalid chunk upload request, retry
        return Response::make('', 400);
    }
}
if ($file->validateFile() && $file->save($destination)) {
    $response = Response::make('pass some success message to flow.js', 200);
}
return $response;

You might also pass params to Flow\Request class https://github.com/flowjs/flow-php-server/blob/master/src/Flow/Request.php#L12 Or you can rewrite this class in a laravel way. I haven’t tested this, but it might work.

0reactions
ghostcommented, Apr 15, 2016

Laravel way instead of $_SERVER['REQUEST_METHOD'] === 'GET' would be if ($request->isMethod('get')) { } where $request is Illuminate\Http\Request injected into method as Request $request

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why am I still getting this file-upload error in Laravel?
The key is that I'm using Axios to send the file to the server. This code properly returns the MIME type for all...
Read more >
3 Helpful Tips For Doing Laravel File Uploads
Stuck with File upload? Laravel file upload is a PHP framework, and by using Filestack's PHP SDK you can find an easy solution!...
Read more >
Request Lifecycle - Laravel - The PHP Framework For Web ...
Lifecycle Overview. First Steps. The entry point for all requests to a Laravel application is the public/index.php file. All requests ...
Read more >
Plain PHP Resumable Large File Uploads in Chunks ... - Morioh
Code available at GitHub Php FlowJs Resumable File Upload ... Use the following composer command to install Flow PHP Server to handle the...
Read more >
Test and deploy Laravel applications with GitLab CI/CD and ...
Create a Container Image ; # Install PHP and composer dependencies RUN apt-get install -qq ; # Clear out the local repository of...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found