来自 filepicker.io JS API v2 的错误 142 在带有裁剪的选择调用后转换调用 UI

Error 142 from filepicker.io JS API v2 convert call after pick call with cropping UI

我使用的是付费 Filepicker.io 帐户。

我通过 JS API 版本 2 从转换调用中返回错误 142。

错误对象的 toString 方法告诉我要包含 filepicker_debug.js 以获取更多信息,但该文件给出了 404,所以这没有帮助。

The docs说142就是"The user's file cannot be converted with the requested parameters." 我传的参数是{width: 240, height: 240}.

我的代码运行一个 pick 操作(它使用裁剪 UI),然后将回调中可用的“Blob”传递给 store 命令(有效)和 convert 命令(无效)。

我尝试删除 store 命令,所以只是 pick 然后 convert,但没有任何变化。

如上所述,我传递的 convert 个选项是 {width: 240, height: 240}。我也尝试传递额外的选项,如 fit:clipfit:scalerotate:exif 但这不会改变任何东西。我还尝试在 pickAndStore 调用之后执行此操作,而不仅仅是 pick;也没有变化。

我没有编辑从 pick 命令返回的“Blob”,它与 store 命令一起工作,所以我认为这不可能成为问题(就像在 a similar issue 中一样)。我不认为我在那里做错了什么。

如果我查看从 Filepicker 返回的 HTTP 响应,它是一个 400 代码并告诉我,例如 [uuid=16CB6B72517940C7] Invalid conversion parameters。如果我查看实际发送的内容,我想我可能会发现问题。

这个特定的 POST 请求已发送到 https://www.filepicker.io/api/file/ndayWb5GTmNyPoAOjSdg/convert?crop=955,621,954,954/convert&_cacheBust=1436084602394&plugin=js_lib,其中包含已发布的表单数据 width: 240, height: 240, storeLocation: "S3", storePath: "storyimg/local/iq84xYTsu1jJaRcq_small.jpg"

GET 参数 crop=955,621,954,954/convert 看起来很可疑。我在“Blob”中看到了属性url: "https://www.filepicker.io/api/file/ndayWb5GTmNyPoAOjSdg/convert?crop=955,621,954,954"。在我看来,库中的某些 JS 并不期望裁剪参数(可能是由裁剪 UI 添加的)存在于此处,并且盲目地添加 /convert 和其余参数。

Filepicker 人员:请解决此问题。

我试图通过在将“Blob”对象传递给 convert 之前编辑它来解决这个问题。解决方法看起来有点像这样:

filepicker.pick({
    cropRatio: 1,
    services: ['convert', pickerType],
}, function (blob) {
    filepicker.convert($.extend({}, blob, {
        url: blob.url.replace(/\/convert\b.*/, ''),
    }), {
        width: 240,
        height: 240,
        crop: blob.url.replace(/.*[?&]crop=([0-9,]+)(?:&|$).*/, '').split(','),
    }, storeOptions, function (blob) {
        console.log("Convert completed successfully", blob);
    }, handleError);
}, handleError);

这很丑陋,经过测试,我发现它实际上根本行不通。作物不发生。如果我删除 widthheight 它会正确裁剪,所以我知道我提取裁剪参数的方式是正确的,但是 widthheight 整个图像都会调整大小,而不仅仅是裁剪部分。

关于这个问题,REST API documentation for convert

Crop and Resize: we strongly recommend against combining a resize (specifying width or height) with the crop functionality, as it has indeterminant effects depending on whether the crop is applied before or after the image is resized.

我开始质疑我为什么要使用这项服务。

似乎除非 Filepicker 修复这些问题,否则我被迫不允许用户裁剪图像,或者仅在我的 store 操作(已经裁剪)之后才执行 convert图像)完成。这意味着我无法并行保存完整尺寸和缩略图。

我们今天进行了一次部署,解决了人们在第一次使用我们的裁剪工具裁剪图像时会收到错误消息,然后尝试获取 url 并将其传递给转换方法的问题。现在,如果您将 url 传递给已经指向转换端点的转换方法,裁剪参数将被解析,生成的图像将以指定的任何方式裁剪和转换。

我们还添加了一个可以设置为 true 的 crop_first 参数。如果此参数设置为 true,则裁剪将在任何其他转换发生之前发生(调整大小、旋转等)。