【问题标题】:ngx-quill-upload with Angular, how to replace the base64-url with a http-urlngx-quill-upload 与 Angular,如何用 http-url 替换 base64-url
【发布时间】:2021-10-22 03:14:51
【问题描述】:

我使用 angular12、ngx-quill-upload 和 quill 编辑器来上传用户帖子。我正在尝试将图像上传到服务器,然后将 url 嵌入到 htmlstring 并将 htmlstring 保存到数据库中。我可以成功地将图像上传到服务器,但是,当我将 htmlstring 保存到数据库时,htmlstring 仍然包含 base64 字符串而不是图像 url。如何禁用 base64 字符串但使用 URL?

这是我的图像处理程序:

imageHandler: {
upload: (file) => {
return new Promise((resolve, reject) => {
if (file.size < 1000000) { // Customize file size as per requirement
console.log("my sas is : " + this.imagesas);
this.blobService.uploadImage(this.imagesas, file, file.name,() => {}).
then(()=>{
resolve("https://example.blob.core.windows.net/post-images/"+file.name)
})
.catch(
()=>{
reject("error")
}
);

let url = "https://example.blob.core.windows.net/post-images/"+file.name;
 console.log(url);
} else {
   reject('Size too large');
    }
    });
  },
  accepts: ['png', 'jpg', 'jpeg', 'jfif', 'apng', 'bmp', 'gif', 'ico', 'cur', 'pjpeg', 'pjp', 'svg', 'tif', 'tiff', 'webp'] // Extensions to allow for images (Optional) | Default - ['jpg', 'jpeg', 'png']
} as Options,

【问题讨论】:

    标签: angular image url


    【解决方案1】:

    如果设置为 json 而不是 html 会更容易。这就是我所做的:

    ReplaceBaseWithAddress(jsonstring: string) {
        let data: QuillVM = JSON.parse(jsonstring);
    
        let baseStrings: string[] = [];
    
        if (data.ops.length > 1) {
          for (let ctr = 0; ctr < data.ops.length; ctr++) {
            if (data.ops[ctr].insert.image) {
            
              let dataimage = data.ops[ctr].insert.image.split(",");
              data.ops[ctr].insert.image = "BASE 64 replaced image with address location here";
              if (dataimage[1]) {
                
                let image64string:string = dataimage[1];
                baseStrings.push(image64string);
              } 
    
            }
          }
        }
    
      }
    

    我希望其他人找到更好的方法。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-07-14
      • 1970-01-01
      • 2019-12-22
      • 2013-04-17
      • 2017-10-07
      • 1970-01-01
      • 2010-12-15
      相关资源
      最近更新 更多