我正在尝试从 Laravel 5 应用程序上传一张照片以存储在 AWS 中。我正在使用 Postman REST 客户端进行测试。当我上传照片时,请求返回一个空数组。有谁知道为什么会这样?这是我的头像 Controller 的代码:
class AvatarController extends Controller
{
public function __construct(AWS $aws)
{
$this->aws = $aws;
}
/**
* Store a new avatar for a user.
* POST northstar.com/users/{id}/avatar
*/
public function store(User $user, Request $request)
{
dd($request->all());
// dd($request->file('photo'));
$file = $request->file('photo');
// $file = Request::file('photo');
// $file = Input::file('photo');
$v = Validator::make(
$request->all(),
['photo' => 'required|image|mimes:jpeg,jpg|max:8000']
);
if($v->fails())
return Response::json(['error' => $v->errors()]);
$filename = $this->aws->storeImage('avatars', $file);
// Save filename to User model
$user->avatar = $filename;
$user->save();
// Respond to user with success
return response()->json('Photo uploaded!', 200);
}
}
最佳答案
找到了答案 - 看起来我的 Postman 中的 header 存在问题。我有 Accept application/json 和 Content-Type application/json。一旦我删除了 Content-Type,一切就都解决了。谢谢!
关于php - dd($请求->全部());返回空数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30334216/