通过axios发送文件时出现500错误

问题描述 投票:0回答:1

首先,我想从外部服务器下载图像,然后我想通过axios将带有该图像的post请求发送到我的laravel REST api,但是当我尝试这样做时,我得到了这个错误。当我通过邮递员发送请求时一切正常。

在这里你是blob响应:

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));
            });

谢谢你,祝新年快乐:)

php laravel apache file-upload axios
1个回答
0
投票

我发现在我的apache error.log中:

[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服务器:)

© www.soinside.com 2019 - 2024. All rights reserved.