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

Uploaded file real name not working #30

Open
henryavila opened this issue May 8, 2020 · 4 comments
Open

Uploaded file real name not working #30

henryavila opened this issue May 8, 2020 · 4 comments

Comments

@henryavila
Copy link

Hi, first of all, thanks for the great plugin, it's helping me a lot.

A problem I'm facing is that I need to save the original file name and it size.
The problem is that the plugin manually set uploaded_file.jpg to original Name.
I can confirm that this happens just with this plugin. The native ImageField works great.

In file PicturePicker.vue I found:

// The default value been set
69: originalName: 'uploaded_file.jpg',

...

// The originalName is been replaced, but for some reason it's not working.
119: this.originalName = file.name
@michapixel
Copy link

Can confirm.

@michapixel
Copy link

You need to use:

->preview(function () {
                    if (!$this->value) return null;

                    $url = Storage::disk($this->disk)->url($this->value);
                    $filetype = pathinfo($url)['extension'];
                    return 'data:image/' . $filetype . ';base64,' . base64_encode(file_get_contents($url));
                })

Otherwise use your own logic.

@michapixel
Copy link

What i'm using now:

->preview(function ($value, $disk) {
        return $value ? Storage::disk($disk)->url($value)  : null;
})
->storeAs(function (Request $request) {
        $filename = $request['slug'];
        $path_parts = pathinfo( $request['product_image']->getClientOriginalName() );
        $filename .= '.' .$path_parts['extension'];
        return $filename;
})

That way the uploaded file/image always gets a unique name (since the slug is unique in my model).

@henryavila
Copy link
Author

Hi @michapixel, thanks for reply.

The problem is not with the file name in storage. The problem is with the original filename uploaded.

I save in DB the original filename uploaded to allow the user download the file with the same name (instead of the random name saved in storage).

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

2 participants