AdonisJs 图片上传

AdonisJs image upload

我是 adonisjs 的新手我目前遇到一个问题,我正在上传图片并出现这样的错误Cannot read property 'subtype' of null 我也不知道javascript.directly 学习 adonisjs

我正在构建 Web 应用程序,需要显示图像 w/AdonisJS

ImageController.js

async imageAdd({ view, params }) {
    const brand = await Brand.find(params.id);
    return view.render("brand_list.logo_up", {
      brand: brand,
    });
  }

   
   

async update({ request, response }) {
           
           let iData = request.only(["logo"]);
           
           const ValidationOptions = {
             types: ["image"],
             size: "5mb",
             extnames: ["png", "gif", "jpg", "jpeg"],
           };
           const imageFile = request.file("logo", ValidationOptions);
           console.log(imageFile);
           let imageUploadPath = Env.get("IMAGE_UPLOAD_PATH");
           let imagePath = Helpers.publicPath(imageUploadPath);
       
           let fileName =
             Math.floor(Math.random() * (999999 - 100000 + 1)) +100000 +"-" +
             new Date().getTime() +"." +imageFile.subtype;
       
           await imageFile.move(imagePath, {
             name: fileName,
             overwrite: true,
           });
       
           let appUrl = Env.get("APP_URL");
           let imageUrl = appUrl + imageUploadPath + "/" + fileName;
           if (!imageFile.moved()) {
             let error = imageFile.error();
             throw new Error(JSON.stringify(error));
           }
           iData.logo = imageUrl;
           await Brand.create(iData);
       
           return response.redirect('/brands')
              }

**when i log the imageFile, imageFile=null**

logo_up.edge

    @layout('main')
    @section('content')
    <form action="/image/{{brand.id}}?_method=PUT" class ='form'method="POST" enctype="multipart/form-data">
        
    {{ csrfField() }}
        <div>
        <input type="file" name="logo"
        id="logo"  />
        <button type="submit" class="btn btn-sm btn-info" class="left-move"> Save </button>
        </div>
    </form>
   

我忘了给控制器取品牌,问题已解决。

async update({ params, request, response }) {
    
    const brand = await Brand.find(params.id);....

检查 bodyparser.js autoProcess 是否正确