-
-
Notifications
You must be signed in to change notification settings - Fork 167
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
are you planning to add upchunk support ? #132
Comments
Hey, I think you can do it by our self? Shoud be quite easy, just implement a new handler :) |
@devArman did you manage to add the support? |
We are implementing upchunk controller. Will submit a pull request in the next couple of days, maybe. It's not as straightforward as just adding a handler lol :D as upchunk has PUT requests instead of actual file uploads. |
Here's how we ended up solving it using the regular range handler via a public function upload_chunked(Request $request)
{
$data = $request->getContent();
Storage::makeDirectory('app/chunks/');
$name = $request->query('name'); // the frontend has to send a unique name for this upload ($uploaded_filename-$random.$ext)
$mime = $request->query('mime'); // frontend has to send the mimetype as well for now, todo: detect mimetype?
File::put($part_path = (storage_path('app/chunks/') . ($part_name = md5($data . microtime(true)))), $data);
$file = new class($part_path, $name, $mime, null, \UPLOAD_ERR_OK, true) extends UploadedFile {
public function isValid(): bool
{
return true;
}
};
$receiver = new FileReceiver($file, $request, ContentRangeUploadHandler::class);
$save = $receiver->receive();
unlink($file->getPathname());
if ($save->isFinished()) {
// todo: check filetype and mime before saving
$path = Storage::putFile('i/' . ( auth()->id() ? : 0 ), $save);
unlink($save->getPathname());
return true;
}
$handler = $save->handler();
return response()->json([
'done' => $handler->getPercentageDone(),
]);
} There are a couple of tricks employed in terms of faking a real system upload. Hope this helps. |
are you planning to add upchunk support ?
Thank you
The text was updated successfully, but these errors were encountered: