首先,我想从外部服务器下载图像,然后我想通过axios将带有该图像的发布请求发送到我的laravel REST api,但是当我尝试执行该操作时,出现了该错误。当我通过邮递员发送请求时,一切正常。
这是您的问题回复:
Blob(3382513) {size: 3382513, type: "image/jpeg"}
size: 3382513
type: "image/jpeg"
__proto__: Blob
size: (...)
slice: ƒ slice()
type: (...)
constructor: ƒ Blob()
Symbol(Symbol.toStringTag): "Blob"
get size: ƒ size()
get type: ƒ type()
__proto__: Object
我的控制器
public function store(Request $request)
{
return Image::make($request->file)->response();
}
JavaScript
async confirmWallpaper(wallpaper) {
let image;
await fetch(wallpaper.image_url)
.then(res => res.blob())
.then(blob => {
image = blob;
});
let data = new FormData();
data.append('file', image);
axios.post('/api/wallpaper', data,
{
header : {
'Content-Type' : 'multipart/form-data'
}
},
)
.then(res => res)
.then(res => {
if("error" in res) {
this.message = res.error.message;
}
if("data" in res) {
console.log(JSON.stringify(res.data));
}
})
.catch(error => {
console.log(JSON.stringify(error.response));
});
谢谢你,新年快乐:)
答案 0 :(得分:0)
我在我的Apache错误中发现了。将此记录为:
[Thu Jan 03 17:56:16.405178 2019] [php7:error] [pid 2548:tid 1716] [client
127.0.0.1:57143] PHP Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 32768 bytes) in C:\\xampp\\htdocs\\wallpapers\\vendor\\symfony\\debug\\Exception\\FatalErrorException.php on line 1, referer: http://laravel.local/panel/
然后我更改了php.ini的内存限制,它可以正常工作
memory_limit=600M
别忘了重新启动apache服务器:)