我正在尝试从Laravel 5应用程序上传照片以存储在AWS中。我正在使用Postman REST客户端进行测试。当我上传照片时,请求返回一个空数组。有谁知道为什么会这样吗?这是我的头像控制器的代码:
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中的标题有问题。我同时接受了application / json和Content-Type application / json。删除Content-Type后,所有问题均已修复。谢谢!
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句