ista0x1's avatar

the audio failed to upload just in production server it works correctly in my local environment.

error : 422 Unprocessable Entity "The audio failed to upload." i updated upload_max_filesize and post_max_size in php.ini and client_max_body_size 100M; in nginx conf but still same error here is the upload controller the problem is in the validation class UploadController extends Controller { public function store(Request $request) { $request->validate([ 'file' => 'nullable|image|mimes:jpeg,png,jpg,gif,svg|max:2048', 'audio' =>'nullable|file|mimes:audio/mpeg,mpga,mp3,wav,aac' ]);

here is when i try to dd($request) before validation +files: Symfony\Component\HttpFoundation\FileBag {#48 #parameters: array:1 [ "audio" => Symfony\Component\HttpFoundation\File\UploadedFile {#33 -test: false -originalName: "bodak-yellow-official-music-video.mp3" -mimeType: "application/octet-stream" -error: 1 path: "" filename: "" basename: "" pathname: "" extension: "" realPath: "/var/www/sportMA/web/public"

0 likes
11 replies
ista0x1's avatar

@jaseofspades88 { "message": "The audio failed to upload.", "errors": { "audio": [ "The audio failed to upload." ] } }

jaseofspades88's avatar

That's a validation issue. Nothing to do with uploading a video. It means your validation rules aren't passing.

1 like
ista0x1's avatar

@jaseofspades88 yes I know but validation it doesn't pass any error in my local env this error just in production the problem might be in size config in nginx

jaseofspades88's avatar

The file size is only relevant in this case if you have a filesize validation rule and the file you're attempting to upload is too large. The simple fact of the matter is that a 422 Unprocessable Entity is, always has been and always will be a validation related issue.

I can see from your horrifically formatted code (I suggest you read a markdown cheatsheet to know how to format your code) that you're not passing the correct mime type of video file anyway...

I do hope, once you resolve this validation issue, you're not going to use this thread as some sort of scratch pad for... '....and now I have this problem....' and so on.

martinbean's avatar

@ista0x1 You’ve set MIME type validation to audio/mpeg,mpga,mp3,wav,aac (which doesn’t seem to be a list of valid MIME types in the first place), but then try and upload a file with a MIME type of application/octet-stream, which is essentially just raw bytes rather than an actual MP3 file.

krisi_gjika's avatar

The error "The audio failed to upload" is likely due to the "file" validation rule. Likely the file you are trying to upload is not reaching the server. Try to increase the post_max_size and upload_max_filesize in the php.ini your server uses to reasonable values.

Keep in mind that a very big file might fail uploading also due to a timeout, depending on the user's connection speed. I would suggest implementing a chunked upload if you expect to deal with large files.

1 like
ista0x1's avatar

@krisi_gjika I already increased the post_max_size but I still face the same error if I upload audio greater than 2Mb

martinbean's avatar

@ista0x1 Yes. You should be using chunked/multi-part uploads for large files, otherwise you’re going to hit a file size limit or memory limit.

krisi_gjika's avatar

@ista0x1 are you sure you updated the right php.ini? make sure the change you did had an effect or try to restart your apache

Please or to participate in this conversation.