由于某种原因,我无法确切指出我的应用程序未能通过请求正文发送文件的原因。我尝试了各种方式配置请求标头,但无济于事。我知道这不是我在Laravel的终点,因为Postman可以很好地工作。
我尝试过的各种头组合:
'Content-Type': 'application/x-www-form-urlencoded',
'Content-Transfer-Encoding': 'multipart/form-data'
OR
'Content-Type': 'multipart/form-data',
'Content-Transfer-Encoding': 'multipart/form-data'
OR
'Content-Type': 'application/json; charset=UTF-8',
'Content-Transfer-Encoding': 'multipart/form-data'
每当我进行端点检查以查看$ request-> file('document')是否为空时,它总是返回true。
这是我的api代码:
public function store(Request $request)
{
$value = $request->file('document')->storeAs(
$request->input('path'), $request->input('name')
);
return response()->json($value, 201);
}
这是使用和失败的头文件的最后一组:
Accept: */*
Accept-Encoding: gzip, deflate
Accept-Language: en-US,en;q=0.9
Connection: keep-alive
Content-Length: 164
Content-Transfer-Encoding: multipart/form-data
Content-Type: multipart/form-data; charset=UTF-8
Cookie: remember_web_59ba36addc2b2f9401580f014c7f58ea4e30989d=eyJpdiI6IjhZMXRwM3BSYnlsMUdlUHQ1OEVzZkE9PSIsInZhbHVlIjoibFJBV3AxaHU0T3BJY1M5UGRQZG5YdmhxTndWYXRRRHFsZlhEZ0tNa1NqWnlFZndwUGdkeGxFNzZXVW53OUxKMWJ0Q0s3VkFxZTM5T1dKUTdQVE5HbHVhcHBoS29rMllQb1wvbUhKeWFMcjdOOGU3elRYWWlyV3daY1duUUZCb1k1amE3aEVHWEN5SkJLZFVCNnNlRlJIa0hVT2FGb1poVjhCZzVOR21EMUttND0iLCJtYWMiOiI2YjFjYTA5MzcyYzcxMDk4OWFmNzJlNTMzMzQ0ODRkYTZmYzEzZDNjYmQ2YTdiNmZhZWFhODc2NWM0MWExMzZiIn0%3D; XSRF-TOKEN=eyJpdiI6Ikh4R1JhSXJ4M1IycmJTNmFsRjRic0E9PSIsInZhbHVlIjoib0xpQzZqaHRRRFQ3V0RQU0lVT3VSdmU4RFwvS3MwSWpSeTdmOURVZE9kRlhPaTBFeWlBOHljQ1F4aGt0VEFIbWwiLCJtYWMiOiI3MjcyMGM5YzIwZjE5NTFkOTQyNjA3MDlmOTJjMjY0OTg2NGViZWY5NzYwZmJlNGEyYmM0MzFmNDYxMDRlN2U5In0%3D; conversion_session=eyJpdiI6InIwc2NRMzZhc1RZdWZtMDl0OFVMaHc9PSIsInZhbHVlIjoiNmY5MjJUYTNteW5zVG9MVmlmXC90a0FCaTlEY3VhS0w2UXYreUtmdG5yUE5IUnpWVE1qTWthemdnSzRKbmE5NWEiLCJtYWMiOiJjNDkzZTVlNzE0YjBhMDRiNDU3ZmQxMzNlZDkzMjQ1MWQ2YTcxMzYxODU0ZGMyYTFkOTZhYjA2ZmUwNDZhOGQ2In0%3D
Host: conversion:8000
Origin: http://conversion:8000
Referer: http://conversion:8000/accounts/1/projects/1?_token=
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36
X-XSRF-TOKEN: // Not pasted here
答案 0 :(得分:0)
我发现我为这些文件分配了错误的帖子数据。一个教程错误地指示了我,然后我发现了另一个教程,向我展示了正确的方法。