【问题标题】:Strapi Image UploadStrapi 图片上传
【发布时间】:2022-11-01 18:24:19
【问题描述】:

我的应用程序中的 /upload 路由有问题。

我可以让它工作和上传,我的问题是 /upload 路线是开放的,任何经过身份验证的人都可以使用它,因此可以随意上传,也可以发布到他们可以控制的整体。例如,我可以为路由设置一个 isAuthenticatedUser 策略来检查它是否是正确的经过身份验证的用户?

谢谢

【问题讨论】:

  • 请提供足够的代码,以便其他人可以更好地理解或重现该问题。

标签: next.js strapi


【解决方案1】:
  const [files, setFiles] = useState();

    const uploadImage = async (e) => {
      e.preventDefault();

      const formData = new FormData();

      formData.append("files", files[0]);

      axios
        .post("http://localhost:1337/api/upload/", formData)
        .then((response) => {
          const imageId = response.data[0].id;

          axios
            .post("http://localhost:1337/api/images", { image: imageId })
            .then((response) => {
              //handle success
            })
            .catch((error) => {
              //handle error
            });
        })
        .catch((error) => {
          //handle error
        });
    };







<form onSubmit={uploadImage}>
      <input type="file" onChange={(e) => setFiles(e.target.files)} />
      <input type="submit" value="Submit" />
    </form>

【讨论】:

    【解决方案2】:

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-01-12
    • 2022-01-11
    • 2022-06-30
    • 1970-01-01
    • 2021-05-10
    • 1970-01-01
    • 2020-11-28
    相关资源
    最近更新 更多