Fajar's avatar
Level 2

Download

I'm confused about this

before this thread appeared I had a problem downloading the file then I tried to fix it and it worked

but after it has been successfully repaired the download cannot be opened

I tried migrate:fresh and tried to upload again, when the download process again it can't

upload function

public function store()
    {
       $upload = Upload::create($this->validateRequest());

       $this->storeImage($upload);

        flash()->success('file berhasi ditambahkan');

        return redirect()->back();
    }

private function validateRequest(){
        return tap(request()->validate([
            'record_id'   => 'required',
            'title'       => 'required',
            'image'       => 'required|image|max:5000',
        ]), function(){
            if(request()->hasFile('image')){
                request()->validate([
                    'image'    => 'required|image|max:5000',
                ]);
            }
        });
    }

private function storeImage($upload){
        if(request()->has('image')){
            $upload->update([
                'image'  => request()->image->store('uploads','public'),
            ]);

            $image = Image::make(public_path('storage/'. $upload->image));
            $image->save();
        }
    }

function download

public function download($id)
    {
        $image = Upload::find($id);

        return Storage::download($image->image);

    }
0 likes
4 replies
Fajar's avatar
Level 2

@Tray2

File not found at path: uploads/ZXKNALQ96e7Xx9h3k03Djf8MXqFj6TlQTx0bwxoW.png
Fajar's avatar
Fajar
OP
Best Answer
Level 2

Done i change with this

return Storage::disk('public')->download($image->image);
Tray2's avatar

You should consider using intervention to upload your images and you should name them something better than the randomly generated temporary name they get from the webserver. If you don't it might overwrite existing files or fail during the move to the storage

Please or to participate in this conversation.