【问题标题】:upload preset must be specified when using unsigned upload cloudinary使用未签名上传云时必须指定上传预设
【发布时间】:2020-11-07 11:29:56
【问题描述】:

我正在尝试使用 cloudinary API_URL 直接从我的前端(Angular 8)上传文件,但仍然收到相同的错误请求(400)和相同的错误“上传预设必须被列入未签名上传的白名单”,即使我尝试过不同的解决方案,例如在 FormData 中提供 preset_name 并在我的 cloudinary 设置中将预设设置为未签名,但仍然无法正常工作。有什么解决办法吗?

我的上传代码:

 const images = new FormData();
images.append('images', file);
images.append('upload_preset', [presetName]);
this.progressBar = true

const req = new HttpRequest('POST', 'https://api.cloudinary.com/v1_1/[cloudName]/image/upload', images, 
    {
     reportProgress: true,
  
   });
this.http.request(req).subscribe(event => {
  if (event.type === HttpEventType.UploadProgress) {
    const percentDone = Math.round(100 * event.loaded / event.total);
    console.log(`File is ${percentDone}% uploaded.`);
  } else if (event instanceof HttpResponse) {
    console.log('File is completely uploaded!');
  }
});

【问题讨论】:

    标签: httprequest angular8 cloudinary


    【解决方案1】:

    Upload preset must be whitelisted for unsigned uploads 错误表示您使用的预设被标记为签名上传。由于您没有执行经过身份验证的 API 调用,即使用签名,因此上传预设必须设置为未签名。如果您还没有,请转到您帐户中的“设置”->“上传”选项卡,并确认您尝试使用的预设的“签名模式”设置为“未签名”。

    此外,我看到您传递了一个名为“图像”的参数。这不是Upload API 的有效参数。请将其更新为“文件”。

    const data = new FormData();
    data.append("file", file);
    data.append("upload_preset", "default-preset");
    

    【讨论】:

    • 非常感谢!它工作得很好!感谢您的帮助
    猜你喜欢
    • 2023-04-01
    • 2019-01-09
    • 1970-01-01
    • 2018-09-18
    • 1970-01-01
    • 2016-05-16
    • 2020-07-03
    • 2016-03-18
    • 2018-08-12
    相关资源
    最近更新 更多