Skip to content
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

Concurrent upload same files fails #44

Open
honzahana opened this issue Jan 30, 2020 · 0 comments
Open

Concurrent upload same files fails #44

honzahana opened this issue Jan 30, 2020 · 0 comments

Comments

@honzahana
Copy link

honzahana commented Jan 30, 2020

I'm working on new version of on-line photo printing software. So I tested your package. In this case often happens that users send the same file.

I enabled duplicate uploads via JS:

var flow = new Flow({
    target: 'upload.php',
    allowDuplicateUploads: true,
});

When you select same file multiple times until first upload is finished only one file is saved.

To easy reproduce use this code (upload.php):

<?php

require_once './vendor/autoload.php';

$config = new \Flow\Config();
$config->setTempDir('./tmp');
$request = new \Flow\Request();
$uploadFolder = './upload/'; // Folder where the file will be stored
$uploadFileName = uniqid()."_".$request->getFileName(); /
$uploadPath = $uploadFolder.$uploadFileName;
if (\Flow\Basic::save($uploadPath, $config, $request)) {
  // file saved successfully and can be accessed at $uploadPath
} else {
  // This is not a final chunk or request is invalid, continue to upload.
}
sleep(10);

And add sleep(5) to /vendor/flowjs/flow-php-server/src/Flow/File.php, line 192.

sleep(5);
if ($this->config->getDeleteChunksOnSave()) {
    $this->deleteChunks();
}

Just before chunks are merged.

Explanation: Flow.js creates same identifier for same fille. Flow-PHP-Server uses this identifier for chunk names (after hasing) = same chunk names for different uploads. When first file is merged chunks for next one are deleted. So another file cannot be created.

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

1 participant