[files-module] - File upload doesn't upload file if filename is already on the folder.

lckamal - 5 months ago

I am uploading a new file named "Profile.jpg" and I found that there is already a file name called "Profile.jpg". Uploader returns the previous row as upload row which is wrong data. User will see other's profile picture as theirs.

public function uploadProfilePicture(Repository $config, FileUploader $uploader, FolderRepositoryInterface $folders)
    {
        $data = \Request::all();
        $image = \Request::file('file');

        if($image){            
            $uploaded_image = $uploader->upload($image, $folders->findBySlug('profile_picture'));
            if($uploaded_image){
                $profile = auth()->user()->profile();
                $profile->profile_picture_id = $uploaded_image->id;
                $profile->save();
                return response()->json(['success' => true, 'thumb' => $uploaded_image->image()->output()]);   
            }
        }
        else{
            return response()->json(['success' => false, 'message' => 'Porfile picture could not be uploaded.']);   
        }
    }

A solution is to give option on uploader to rename file name on upload. so that we can change unique name with user id or something.

any idea?

ryanthompson - 5 months ago

There's a function lying around for unique-ifying names somewhere around here. I'll see if I can dig it up.

lckamal - 5 months ago

ok please.