我们如何使用 FilePond 将图像 Direct Creator Upload URL 上传到 Cloudflare?

发布于 2025-01-14 09:08:15 字数 2034 浏览 2 评论 0原文

使用 FilePond 上传到 Cloudflare Images 失败,返回 400。我正在使用一个简单的表单并排测试它。我从我们的 api 获取 Direct Creator Upload URL,将其传递给两个组件。表单总是成功,而 FilePond 总是失败。有人可以建议修复吗? https://developers.cloudflare.com/images /cloudflare-images/upload-images/direct-creator-upload/

它返回 400 错误请求。来自 CloudFlare 或 FilePond 的人可以弄清楚为什么 CF Images 响应来自 FilePond 的请求格式错误吗?

import { useState } from "react";
import { FilePond, registerPlugin } from "react-filepond";

import FilePondPluginImagePreview from "filepond-plugin-image-preview";
import FilePondPluginFileValidateType from "filepond-plugin-file-validate-type";
import DefaultButton from "./BaseComponents/defaultButton";

// Register the plugins
registerPlugin(
  FilePondPluginImagePreview,
  FilePondPluginFileValidateType,
);

interface Props {
  uploadURL: string;
}

export default function UploadAvatar(props: Props) {
  const { uploadURL } = props;
  const [files, setFiles] = useState<any>([]);
  return (
    <>
      {/* This simple form uploads successfully */}
      <form action={uploadURL} method="post" encType="multipart/form-data">
        <input type="file" id="myFile" name="file" />
        <DefaultButton type="submit">Upload Image</DefaultButton>
      </form>

      {/* FilePond upload fails with a 400 */}
      <div className="h-44 w-44 rounded-full ring-4 ring-light-control-accent-rest dark:ring-dark-control-accent-rest">
        <FilePond
          files={files}
          onupdatefiles={setFiles}
          allowMultiple={false}
          maxFiles={1}
          server={uploadURL}
          name="file"
          labelIdle='Drag & Drop your files or <span class="filepond--label-action">Browse</span>'
          acceptedFileTypes={["image/*"]}
          onerror={(error) => console.log(error)}
        />
      </div>
    </>
  );
}

Uploading to Cloudflare Images with FilePond fails returning a 400. I'm testing it side by side with a simple form. I get the Direct Creator Upload URL from our api, pass it in to both components. The form always succeeds, while FilePond always fails. Can anyone suggest a fix please?
https://developers.cloudflare.com/images/cloudflare-images/upload-images/direct-creator-upload/

It's returning a 400 Bad Request. Can someone from CloudFlare or from FilePond figure out why CF Images is responding that the request from FilePond is malformed?

import { useState } from "react";
import { FilePond, registerPlugin } from "react-filepond";

import FilePondPluginImagePreview from "filepond-plugin-image-preview";
import FilePondPluginFileValidateType from "filepond-plugin-file-validate-type";
import DefaultButton from "./BaseComponents/defaultButton";

// Register the plugins
registerPlugin(
  FilePondPluginImagePreview,
  FilePondPluginFileValidateType,
);

interface Props {
  uploadURL: string;
}

export default function UploadAvatar(props: Props) {
  const { uploadURL } = props;
  const [files, setFiles] = useState<any>([]);
  return (
    <>
      {/* This simple form uploads successfully */}
      <form action={uploadURL} method="post" encType="multipart/form-data">
        <input type="file" id="myFile" name="file" />
        <DefaultButton type="submit">Upload Image</DefaultButton>
      </form>

      {/* FilePond upload fails with a 400 */}
      <div className="h-44 w-44 rounded-full ring-4 ring-light-control-accent-rest dark:ring-dark-control-accent-rest">
        <FilePond
          files={files}
          onupdatefiles={setFiles}
          allowMultiple={false}
          maxFiles={1}
          server={uploadURL}
          name="file"
          labelIdle='Drag & Drop your files or <span class="filepond--label-action">Browse</span>'
          acceptedFileTypes={["image/*"]}
          onerror={(error) => console.log(error)}
        />
      </div>
    </>
  );
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

赴月观长安 2025-01-21 09:08:15

好的,解决方案是控制文件处理,以确保我们只发送文件。

使用此处概述的方法: https://pqina.nl/filepond/docs /api/server/#process-1url-to-api 替换为我们从 Cloudflare API 获取的 Direct Creator Upload url。如果您使用 TS,请注意,截至今天,存在类型不匹配的问题,从而导致错误。只需从函数参数中删除传输选项即可修复。

更多详细信息请参见:https://github.com/pqina/filepond/issues/818

Okay so the solution to this is to take control of the file processing to ensure we are only sending the file.

Use the method outlined here: https://pqina.nl/filepond/docs/api/server/#process-1 replacing url-to-api with the Direct Creator Upload url we get from Cloudflare's API. If you are using TS note that as of today there is a type mismatch which causes an error. Just remove transfer options from the function params to fix.

More details here: https://github.com/pqina/filepond/issues/818

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文