upload an image to image server using http client in laravel

  curl, http, laravel, php

i’ve been trying to upload an image to an image server but although i send the image as base64 it gives me an error of "no image" , one of my coworkers told me to use http::asForm

  public static function uploadImage($systemID, $itemID, $base64Payload, $filename){

    $url = "http://192.168.1.57/put/";
    $authToken = "//ommitted//";
    // what post fields?


    $response = Http::withBody(
        $base64Payload, 'image/jpeg'
    )->asForm()->post($url , [

        'systemID' => $systemID,
        'itemID' => $itemID,
        'base64Payload' => $base64Payload,
        'filename' => $filename,
        'authToken' => $authToken,
    ]);

    return $response;


}

and im thinkn it’s because of that that the image doesn’t get uploaded successfully , what do u guys think?

public function UploadImage(Request $request){

    $customer = auth()->guard("api")->user();
    $lbCustomer = AppModelslocalbeecustomerCustomer::where('id' , $customer->id)->first();

    $logoImageName = "";
    if ($request->hasFile('image') && $request->file('image') > 25) {
        $image =  base64_encode(file_get_contents($request->file('image')->getRealPath()));
        //return $image;
        $imageType = $request->file('image')->getClientOriginalExtension();
        $imageunique_1_name = md5(uniqid() . microtime());
        $response = UploadImage::uploadImage(2, 8 , $image , $imageunique_1_name );

        $logoImageName = $imageunique_1_name . "." . $imageType;

        $lbCustomer->customer_image = $logoImageName;
        $lbCustomer->save();

            return $response;




    }else{
        return response()->json(null , 401);
    }


}

Source: Laravel

Leave a Reply