Qasim Ali
Qasim Ali

Reputation: 597

malformed utf-8 characters possibly incorrectly encoded

I have encoded image to base64 in iOS and sending it to server and then using base64_decode() on that string. But it is giving an error

malformed utf-8 characters possibly incorrectly encoded

i am doing this in laravel and using php core function;

public function createIdea(Request $request) {
   $filename = str_random(8);
   $imageStr = $request->input('idea_image');
   $decodeImage = base64_decode($imageStr);
   $image = imagecreatefromstring($decodeImage);
     if ($request->hasFile($image)) {
          $filename = $request->file($image)->getClientOriginalName();
          $moveImage = $request->file($image)->move('images', $filename);
     }
   $idea = new Idea();
   $idea->idea_title = $request->input('idea_title');
   $idea->idea_info = $request->input('idea_info');
   $idea->idea_image = "images/".$filename;
   $idea->idea_location = $request->input('idea_location');
   $idea->idea_description = $request->input('idea_description');
   $idea->idea_description = $request->input('selection');
   $idea->user_id = \Auth::id();
   $idea->save();
   $ideaId = $idea->id;
     if ( ! $idea->id ) {
          $statusCode =404;
          response()->json(array('Status:' => 'Idea Creation FAILED'),$statusCode);
    }else{
          $response = $idea->toJson();
          $statusCode =200;
          return response()->json(array('Status:' => 'Idea Created Successfully', 'ideaId' => $ideaId, 'image' => $imageStr),$statusCode);
}

Any help would be appreciated.

Upvotes: 2

Views: 2936

Answers (1)

Matteus Barbosa
Matteus Barbosa

Reputation: 2743

Encoding the blob in base64 before serving the data in any language will allow you to transfer BLOB data as safe strings!

Upvotes: 1

Related Questions