[files-module] - File upload doesn't upload file if filename is already on the folder.
Created 7 years ago by lckamal

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');

            $uploaded_image = $uploader->upload($image, $folders->findBySlug('profile_picture'));
                $profile = auth()->user()->profile();
                $profile->profile_picture_id = $uploaded_image->id;
                return response()->json(['success' => true, 'thumb' => $uploaded_image->image()->output()]);   
            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  —  7 years ago

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

lckamal  —  7 years ago

ok please.