在Octobercms上传blob头像

Upload a blob avatar in Octobercms

我正在使用 October 并使用 JWT Auth 在 Vue.js(Quasar 框架)中开发一个前端应用程序。 在 Vue 中,我使用 FileReader 读取了 .jpg。结果,我有一个 blob 发送到 October,其中包含配置文件参数和 POST axios 请求以更新现有用户配置文件。

10 月,我在 route.php 中有一个插件 API,其中包含以下代码。 似乎我检索了 blob,但是当我尝试将其存储为 file 时,我存储的图像不一致或 October 错误代码如下:

我可以发送原始图像吗?如何将它们存储在 October 文件中?谢谢

    Route::post('Change-Profile', function (Request $request) {
       $user = new User;
       $user->street_addr = $request->street_addr;

       $file = new System\Models\File;
       $file->data = Input::file( $request->avatar );
       $file->is_public = false;
       $file->save();

       $user->avatar = $file;
       $user->save();

因为我在这个微不足道的问题上花费了太多时间,所以我想分享一下我在 Hardik 的帮助下做出的最终解决方案。再次感谢!

        $bIsAvatar = true;
        $user = new User;
        $user_email = $request->email;

        $rules = [
            'email' => 'required|email|min:6',
            'username' => 'required|string|min:5',
            'zip' => 'string|min:1|max:5',
            'avatar' => 'image|mimes:jpeg,png,jpg,gif|max:10000'
        ];

        $validation = Validator::make(Input::all(), $rules);
        if ($validation->fails()) {
            return response()->json([
                'Error' => 'User : ' . $user_email ,
                'Champs invalides : ' . $validation->messages()
            ], Response::HTTP_BAD_REQUEST);
        }

        $user = User::findByEmail( $user_email );
        if (!$user || $user->isBanned() || !$user->is_activated) {
            return response()->json(
                ['Error' => 'User non trouvé ou non autorisé : ' . $user_email ], Response::HTTP_NOT_FOUND
            );
        }

        $user->name = $request->name;
        $user->surname = $request->surname;
        $user->email = $request->email;
        $user->street_addr = $request->street_addr;
        $user->city = $request->city;
        $user->zip = $request->zip;
        $user->phone = $request->phone;
        $user->mobile = $request->mobile;
        $user->about_me = $request->about_me;

        if ( $request->avatar == null || empty($request->avatar) ) $bIsAvatar = false;
        else {
            $user->avatar = Input::file('avatar');
            $user->avatar->is_public = false;
        }
        $user->save();
        if ($bIsAvatar) {
            $avatar_path = $user->avatar->getPath();
            //$resultat = "User " . $user->email . " : profil mis à jour avec l'avatar=" . $avatar_path;
            $resultat = "Profil mis à jour avec avatar" . $user;
        } else
            //$resultat = "User : " . $user->email . " : profil mis à jour sans avatar";
            $resultat = "Profil mis à jour sans avatar" . $user;

        return response()->json($resultat);
    });