0

I want to upload a file via post method using postman, After sending the request i read the request data and it's empty!

Code:

/**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        return response()->json(["dbug" => $request->all()],200); // request is empty!!!
        // return dd($request);
        $validator = Validator::make($request->input()->all(), [
            "name" => ["required", "string"],
            "type" => ["required", "string"],
            "file" => ["required","file", "size:<=1048576"] // maximum file size is 1 GB
        ]);

        if($validator->fails()){
            return response()->json(["error" => $validator->errors()], 400);
        }
        $date = date("ymddhiss");
        return response()->json(["dbug" => $date],200);
    }

In postman, I'm using form-data to upload a file. Could you please help me?

  • 1
    It's probably related to "Content-Type: multipart/form-data". Take a look to this answer: https://stackoverflow.com/questions/16015548/tool-for-sending-multipart-form-data-request – senty Dec 25 '20 at 21:02
  • Exactly! it was on: `content-type: JSON/Application`. By setting the `content-type` to what you said it's working just fine, thank you. – Ali Naderi Parizi Dec 26 '20 at 03:20

0 Answers0