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

are you planning to add upchunk support ? #132

Open
devArman opened this issue Apr 7, 2022 · 4 comments
Open

are you planning to add upchunk support ? #132

devArman opened this issue Apr 7, 2022 · 4 comments

Comments

@devArman
Copy link

devArman commented Apr 7, 2022

are you planning to add upchunk support ?
Thank you

@pionl
Copy link
Owner

pionl commented Apr 7, 2022

Hey, I think you can do it by our self? Shoud be quite easy, just implement a new handler :)

@pionl
Copy link
Owner

pionl commented Apr 27, 2022

@devArman did you manage to add the support?

@soulseekah
Copy link

soulseekah commented Aug 2, 2022

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.

@soulseekah
Copy link

soulseekah commented Aug 4, 2022

Here's how we ended up solving it using the regular range handler via a put() route:

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.

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

No branches or pull requests

3 participants