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

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

问题描述

当我尝试将带有邮递员的文件发送到我的 Laravel api 时,结果总是返回NULL"

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

我的控制器看起来像这样:

my controller look like this:

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)

内容类型 - 多部分/表单数据

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

我的问题和这篇文章中的问题一模一样:在 Laravel 4 中测试文件上传时是否更正 Postman 设置?

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

如果我使用资源控制器并从浏览器输入 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
    }
}

但是,如果我将路由修改为例如 post::(controller@store) 并通过邮递员发送图像,则会收到一条错误消息,指出未定义索引:图像"

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"

推荐答案

如果您想使用 Postman 和 Laravel 测试文件上传,只需删除 Postman 中的 Content-Type 标头设置.

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天全站免登陆