Home > Back-end >  upload avatar with some key value data in Postman for laravel web application
upload avatar with some key value data in Postman for laravel web application

Time:07-11

any body can help me i wanna make a register which is have these parameter

this is my RegisterRequest for validation

 public function rules()
    {
        return [
            'name'     => 'required',
            'email'    => 'required|email|unique:users,email',
            'username' => 'nullable|string|min:5|unique:users,username',
            'avatar'   => 'nullable|mimes:jpge,jpg,png',
            'password' => 'required|string|min:5',
            
        ];
    }

and this is my Postman Setup Headers setup enter image description here

Body / form-data setup enter image description here

Body /raw enter image description here


and this is my register method dd() code

 public function register(RegisterRequest $request)
    {

        dd(
            $request->all(),
            $request->avatar,
            $request->hasFile('avatar'),
            $request->file('avatar')
        );


    }

and this is the result in the Postman

enter image description here

CodePudding user response:

If you post JSON you need to encode your image to base64 or link (url) to image and post it in the body parameter, Also change your validation to base64 or url. try this:

{
  "name" : "ali",
  "email" : "[email protected]",
  "username" : "ali",
  "avatar" : "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAJYAAACWCAYAAAA8AXHiAAAAAXNSR0IArs4c6QAACQZJREFUeF7t3DmIVE0QAOBeEFk3GVgFXcyWAQNTA0GMzU0MPCLBwAMEI0XxwFgQDxSMPMBAc2M1WxYNhWEw0F0DXTBZNxup1h57nm/m9Xt9VVXXJM7s9FFd9dnd /5jbmVlZbS4uKjm5 eVvCQDvhnY2tpSGxsbam44HI7gTb/fV71ez3dc6V9wBn7 /KkGg4GCjWpubW1ttLCwoH8guApW4bl0gwoMbW5u/oG1tLSk7C9k5/LMcmHdq3bW19f/wYJcCK7CRARYbp2Z/2AJrgCZLmiIaRtRLSzBVZAMj6XOOt2mwhJcHhkvoGvTlWkmLMFVgJAOS2xCBUM2whJcHTLPuIsLKmdYgouxlBZLc0XVCpbgalEBhk3boGoNS3AxFOOwpLaoOsESXA6VYNSkC6rOsAQXIzkzltIVlRcswcUblw8qb1iCiycuX1RBYAkuXrhCoAoGS3DxwBUKVVBYgos2rpCogsMSXDRxhUYVBZbgooUrBqposAQXDVyxUEWFJb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vVt2/fmmEJKuf6R2tYt2NVJ7PbwM5RdxTax2YVij1eHazqfPYvCN /f9c76MOHD9XGxoaCz3DUmqP7vx1LUEWz0mpgV1jmMv/69euJ 1d1B4Pxzp49q4 tU6dO/Xepd4VljjuAZN5v27ZN37ngN8r79 /r 9oELEHVqvZRG1dhVQtvPsNzJ7h0z3rcYPfdtWuX0x3LvpfB NOOYvO4AdDCb6Hnz59XvV7vH6yFhQU1GAxUv9/XX8grbwbqdqzqA1J4JGEfdXUPSE0feOhp2tq/FVYfvtqX9 oD0upD0OoD0hs3bqgvX75oQ5ubm2puOByO4JwUVHkxcZjdnHqLi4tqbmVlZQRv5ufnOaxN1pA5A1tbW/pC/xuptao143LiCQAAAABJRU5ErkJggg==",
  "password" : "123456",
  "password_confirmation" : "123456",
}

CodePudding user response:

Its solved By removing this from Headers

Content-Type : application/json

CodePudding user response:

use form-data instead of raw in postman please check screenshot https://prnt.sc/XP4UA0rHKoOS

  • Related