发送文件,邮递员Laravel API

编程入门 行业动态 更新时间:2024-10-27 08:36:53
本文介绍了发送文件,邮递员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"

我的邮递员配置是:

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

我的问题是完全一样的人在这个职位: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

本文发布于:2023-10-29 04:17:35,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1538702.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:邮递员   文件   API   Laravel

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!