INVALID_EXTENSION使用 ng2 图像工具



我正在使用离子2。

我从火力基地检索了图像。

但是我需要调整此图像的大小。

这是我的函数

var someImage:any="https://firebasestorage.googleapis.com/v0/b/apartments-ea9e5.appspot.com/o/admin%2Fsample-1487416146311.jpg?alt=media&token=e61d2573-acd2-4284-b0b3-f45a1fc450cc";
     this.ng2ImgToolsService.resize([someImage], 100, 100).subscribe(result => {
            //all good, result is a file
            console.info(result);
        }, error => {
          console.log("err");
          console.log(error);
            //something went wrong 
            //use result.compressedFile or handle specific error cases individually
        })

我得到了这个错误。

如何解决此问题。 或任何其他调整图像大小的方法

error:INVALID_EXTENSION
reason: "The provided File is neither of type jpg nor of type png."

好吧,我遇到了同样的问题,我修复了这个问题,如下所示。

有一个名为原始图像的文件(通过文件上传获得(,我将其克隆到另一个名为modifieldImage的文件

克隆的代码如下所示

const modifieldImage= new File(
          [uploadImage.originalImage],
          uploadImage.originalImage.name,
          {
            type: uploadImage.originalImage.type
          }
        );
//then call the api
this.ng2ImgMax .resizeImage(modifieldImage, 1600, 1176) ...

尝试在创建文件时添加"类型"。这应该可以解决问题。

在您的场景中,我相信"someImage"的类型是空的。 尝试将其克隆到另一个文件,并将类型添加到 FilePropertyBag 中

希望它对某人有所帮助。

最新更新