0

I'm trying to upload a file to my Laravel 8 API which will eventually be consumed via a job and processed. I'm using Laravel's Storage method, and have a POST endpoint with a controller action to import my file.

However, when trying this through Postman, I get the following error:

Call to a member function storeAs() on null

What am I missing from my Postman config to get the file?

My controller:

<?php

namespace App\Http\Controllers;

use Illuminate\Http\File;
use Illuminate\Support\Facades\Storage;
use Illuminate\Http\Request;

class CsvController extends Controller
{
    /**
     * Import CSV
     *
     * @param  Request  $request
     * @return Response
     */
    public function import(Request $request)
    {

        $someID = 5;
        $request->file('csv')->storeAs(
          'bulk-csvs', $someID
        );
        // Storage::disk('local')->put('example.txt', 'Contents');

        return response()->json([
          'file' => $request->file('csv'),
          'success' => true,
          'message' => 'CSV imported'
        ], 200);

    }

}

And my Postman config:

enter image description here

Ryan H
  • 2,620
  • 4
  • 37
  • 109
  • 2
    You must define an file input under `csv` field instead of a text – Thanh Dao May 14 '21 at 10:02
  • You are just sending a string, but you will have to send a file https://stackoverflow.com/questions/39037049/how-to-upload-a-file-and-json-data-in-postman – Aless55 May 14 '21 at 10:04

0 Answers0