0

I am using cloudinary to upload images on my Laravel application. When I try to upload images using my mobile device, I get this error:-

Cloudinary\Error: Missing required parameter - file

When I try uploading from my laptop, it works well. This is my code:

$photos = $request->file;
if(isset($request->file)){

    foreach ($photos as $photo){

        $file = $photo;
        Cloudder::upload($file->getPathname());
        $response = Cloudder::getResult();
        $path = $response['secure_url'];
        $publicId = Cloudder::getPublicId();
        $file_size = $file->getClientSize();
        //create record
    }
}

Please what might be the problem?

Vikash Pathak
  • 3,444
  • 1
  • 18
  • 32
shekwo
  • 1,411
  • 1
  • 20
  • 50

2 Answers2

0

maybe the $file is empty? Can you please check this?

Yakir Perlin
  • 174
  • 4
  • It can't be. I made it compulsory. $validator = Validator::make($request->all(), [ 'name' => 'required', 'description' => 'required', 'file' => 'required' ],[ 'file.required' => 'Please add Photo(s) for this Product' ]); – shekwo Jun 12 '19 at 12:01
0

Use following code

if(isset($request->hasFile(file))){

foreach ($request->file('file') as $photo){

    $file = $photo;
    Cloudder::upload($file->getPathname());
    $response = Cloudder::getResult();
    $path = $response['secure_url'];
    $publicId = Cloudder::getPublicId();
    $file_size = $file->getClientSize();
    //create record
} }
Vipul Prajapati
  • 203
  • 2
  • 4