Issue uploading audio file to laravel from digital ocean app platform

58 Views Asked by At

I am getting issues not receiving the audio from the payload in my laravel project. I have a tested the file upload from localhost and it works but when i try it on the digital ocean app platform i get an issue.

So here is what i did. Below is my payload from a form in the blade view and the payload looks the same only change is on the header values because the crsf-token differs.

data: {"category":"3","subcategory":"","title":"Test2","description":"Test3","thumbnail_link":"","media_type":"0","media_link":"","duration":"07:53","is_free":"0","can_download":"0","can_preview":"0","preview_duration":"60","notify":"true"}
thumbnail: (binary)
audio: (binary)

Now ofcourse there is a controller that is handling the requests


public function saveNewAudio(){
  // Upload image file
  $thumb_upload = $this->upload_thumbnail();

  // Upload audio file
  $audio_upload = $this->upload_audio();
}

Now in the upload_thumbnail method is the code below

 public function upload_thumbnail()
    {
        $thumbnail = request()->file('thumbnail');
        $newName = time() . '.' . $thumbnail->getClientOriginalExtension();
        request()->file('thumbnail')->storePubliclyAs(
            'thumbnails',
            $newName,
            's3'
        );
        return ['ok', $newName];
    }

This works for both the localhost and the project running on digital ocean app platform. Now i had a similar code snippet for the upload_audio but it kept failing. So after many research tips i tried to check whether first of all the audio file is received. So i wrote a code snippet to check if the audio file is passed

public function upload_audio()
    {
        if (request()->hasFile('audio')) {
            $audio = request()->file('audio');
            // Your code here to process the audio file
            return ['error', 'Audio file received.'];
        } else {
            return ['error', 'Audio file not received.'];
        }
    }

Now here is where is becomes interesting, the response on the localhost is

Audio file received.

But when i checked on the code running on the digital ocean app platform, the response is

Audio file not received

Implying that there is an issue with the audio file being uploaded, i tried even changing the filename to remove spaces before uploading but no solution. My question is what would be the problem and how would i resolve it.

Thanks in advance

0

There are 0 best solutions below