rezuankassim's avatar

JSON file become text/plain in server

Hi guys, I have Laravel project in a server running apache2 and when I upload json file and in controller I ran

$request->file('file')->getMimeTypes()

and I got this output

text/plain

but when I try in local, I got

application/json

What should I do to retain the file type for application/json ?

0 likes
9 replies
MichalOravec's avatar

@rezuankassim Try

$request->file('file')->getClientMimeType();

And I think getMimeTypes() should be getMimeTypes() in your example.

1 like
rezuankassim's avatar

I am able to get the output application/json but why when I save it to the storage in the server, the json file will become .txt file? is there anything in the apache2 configuration that I missed out? or this is a Laravel issue?

rezuankassim's avatar
	Project::create([
		'file' =>  $request->file('file')->store('uploads'),
	])

This is the code where I store the file

MichalOravec's avatar

@rezuankassim Try

$file = $request->file('file');

Project::create([
    'file' => $file->storeAs('uploads', $file->getClientOriginalName().$file->extension()),
]);
rezuankassim's avatar

@michaloravec it does save the file into .json, why does the file extension become text/plain in the server? while in my local the file extension is still application/json?

Please or to participate in this conversation.