n1crack / vuefinder

Empower your Vue.js applications with this versatile and customizable file manager component, simplifying file organization and navigation.
https://vuefinder.ozdemir.be
MIT License
259 stars 75 forks source link

Bug: file uploading doesn't work with any type of files #59

Closed vinraelll closed 4 months ago

vinraelll commented 4 months ago

When trying to upload any type of files get an error from Uppy package dependency used in Vuefinder:

image

I've tried to upload various types of images (webp, png, jpg), audio files (mp3), but result remains the same.

image

Vuefinder usage in my project:

image image
n1crack commented 4 months ago

It seems it is related to backend server.

I'll check it asap. Until then; be sure to have latest version of php backend library.

vinraelll commented 4 months ago

be sure to have latest version of php backend library.

Updated lib on our server to the latest version. Unfortunately, the issue remains. telegram-cloud-photo-size-2-5420320093184844013-x

n1crack commented 4 months ago

What is the response from the server when you click the upload butt?

Is it a redirection or it returns an error?

Because it seems it can't parse the returned data.

vinraelll commented 4 months ago

After clicking on upload button the plugin makes three unsuccessful requests to the server and all have the same response.

image
n1crack commented 4 months ago

Something happens here, If you can remove try-catch blog, you can see the actual error. Not sure what happens for now.

https://github.com/n1crack/vuefinder-php/blob/97562dd1895aee5f31a6607d4d68d43285cf8d93/src/VueFinder.php#L108-L124

Temporary you can do:

//      try {
            if (!array_key_exists($query, $route_array)
                || $route_array[$query] !== strtolower($this->request->getMethod())) {
                throw new Exception('The query does not have a valid method.');
            }

            $adapter = $this->storageAdapters[$this->adapterKey];
            $readonly_array = ['index', 'download', 'preview', 'search'];

            if ($adapter instanceof ReadOnlyFilesystemAdapter && !in_array($query, $readonly_array, true)) {
                throw new Exception('This is a readonly storage.');
            }

            $response = $this->$query();
//        } catch (Exception $e) {
//            $response = new JsonResponse(['status' => false, 'message' => $e->getMessage()], 400);
//        }
stereoalina commented 4 months ago

Hello,

I believe I know what happened.

We have POST request /api/v1/remote-control-panel/file-manager?adapter=local&path=local%3A%2F%2Fpage_builder&q=upload with payloaded image and content-type: application/json

The exception is thrown here: image image

I think it's no $this->request at this step. I've found where it inizializing:

image

So when we have POST method and our content-type is not application/x-www-form-urlencoded, the "request" buddy has not inizialized.

n1crack commented 4 months ago

I will fix it tonight. Thx for reporting.

I am planning to rewrite the backend library from scratch, when I have time, also considering a new backend package for Laravel with additional features.

Also, need to create an OpenApi docs for backend.

vinraelll commented 4 months ago

Great, sounds good.

I am planning to rewrite the backend library from scratch, when I have time, also considering a new backend package for Laravel with additional features.

I will fix it tonight. Thx for reporting.

Thanks for rapid response

n1crack commented 4 months ago

Well, the problem was because of "Content-Type". It was using 'application/json' instead of 'multipart/form-data" when uploading.

It should work for now, just sent a fix. I'll refactor the code asap as I mention above.

Thanks for reporting.

vinraelll commented 4 months ago

It should work for now, just sent a fix.

Updated the package - all works fine for now, thanks. Files upload without any problems now. I guess, we can mark the issue as completed.