Emokores's avatar

Download zip files

I'm trying to download a zip file I uploaded to my Laravel project in the path storage/app/zips/... but whenever I try to download the file the page freezes, gets slow and instead brings me a modal with symbols and weird characters loaded on it, yet I expect to see the file downloading in the browser. When I try to dump the existence of the file with dd(Storage::disk('local')->exists($file_url)), I also get the result false yet the file exists and the path is correct.

$file_url = Storage::path($task->file_url);  //* path: path/to/laravel_project/storage/app/zips/file.zip

This is the download code:


public function download(Task $task)
{
     $file_url = Storage::path($task->file_url);

     return response()->download($file_url, $task->task_name);
}

I can't see the fault. Or is there a special way to download zip files?

0 likes
6 replies
Emokores's avatar

@Tray2 Thanks. I read the posts and understood the concept. Thank you! I've learned something new.

Emokores's avatar

@Sinnbeck Changing it to an anchor tag actually did the trick! It seems Inertia <Link /> tags usually make AJAX calls to the server. Thanks a lot! I'll keep learning.

Sinnbeck's avatar

@Emokores correct. And if it does not get an inertia response, it opens a modal with the result

johnDoe220's avatar

for upload file,first run

php artisan storage:link

step 2

public function store(Request $request){
	Post::create([
		'zip' => $request->zipinput->store('zipdir');
	]);
}

step 3 - download

public function download($id)
{
	$post = Post::find($id);
return Storage::download($post->zip);
}

Please or to participate in this conversation.