发送文件,邮递员Laravel API [英] Send file with postman to Laravel API

查看:271
本文介绍了发送文件,邮递员Laravel API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试发送一个文件,邮递员我Laravel API的结果总是返回NULL

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

我的控制器是这样的:

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


}

和我的路线文件:

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

但是,当我尝试在邮递员发送图像,我得到的结果NULL

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

我的邮递员配置是:

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

内容类型 - 的multipart / form-data的

Content-Type - multipart/form-data

表单数据

图像 - test.jpg放在

image - test.jpg

我缺少什么?

我检查的php.ini,让我有足够的上传空间

I've checked php.ini so that I have enough space for uploads

我的问题是完全一样的人在这个职位:
<一href=\"http://stackoverflow.com/questions/23441991/correct-postman-settings-when-testing-file-uploading-in-laravel-4\">Correct邮差设置在Laravel 4测试文件上传时?

My problem is exactly like the one in this post: Correct Postman Settings when testing file uploading in Laravel 4?

不过,他的解决方案没有工作。我已经检查了我的php.ini

But his solution didnt work. I have already checked my php.ini

在code波纹管工作,如果我使用一个资源控制器并输入URL形成一个浏览器:

The code bellow works if I use a resource controller and enter the url form a 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 modify my route to eg post::(controller@store) and send the images with postman it get an error saying that "Undefined index: images"

推荐答案

如果你想与邮差和Laravel测试文件上传只需删除内容类型头的邮差设置。

if you want to test file uploads with Postman and Laravel simply remove the Content-Type header setting in Postman.

这篇关于发送文件,邮递员Laravel API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆