Send Postman File to Laravel API

When I try to send a postman file to my Laravel API, the result always returns "NULL"

my controller looks like this:

public function store() { $file = Input::file('image'); var_dump($file); } 

And my route file:

 Route::post('test', ' TestController@store '); 

But when I try to send the image to the postman, I get the result "NULL"

My postman config:

http://app.dev/test (POST)

Content-Type - multipart / form-data

Data form

image - test.jpg

Did I miss something?

I checked php.ini so that I have enough space to load

My problem is exactly the same as in this post: Correct postman settings when testing file uploads in Laravel 4?

But his solution did not work. I already checked my php.ini

The code below works if I use the resource controller and enter the URL from the browser:

 public function store() { $input = Input::all(); $path = public_path() .'/images/123/'; $inpusqt = Input::file('images'); $i = 1; File::exists($path) or File::makeDirectory($path); foreach($inpusqt as $file) { $filExt = $file->getClientOriginalExtension(); $ext = '.' . $filExt; $lol = Image::make($file->getRealPath()); $lol->heighten(258)->save($path . $i . $ext); $i++; //increment value to give each image a uniqe name } } 

But if I change my route, for example, to post: :( controller @store) and send the images to the postman, he will receive an error message: "Undefined index: images"

+8
file api php mysql laravel
source share
3 answers

If you want to test file downloads using Postman and Laravel, just remove the Content-Type header parameter in Postman.

+38
source share

When you select "form-data" in PostMan, it automatically sets the header to "Content-Type: application / x-www-form-urlencoded".

I just removed the cap and it worked :)

0
source share

If you send a request to download the Postman form file, you should also include the Content-Type: multipart / form-data header in it and select form-data, this field should contain a file, not text. Also, be careful only with POST, you can upload a file with PUT and PATCH, it does not work.

0
source share

All Articles