我对云和棱角分明是陌生的。我一直在寻找一种方法来上传图像到cloudinary,而不使用SDK作为cloudinary给我们使用post API上传图像的选项,我尝试了以下,但没有成功。
uploadImage(event) {
var that = this;
this.create_blob(event.srcElement.files[0], function (blob_string) {
that.http.post('https://api.cloudinary.com/v1_1/image/upload/', { file: blob_string}).subscribe(res => {
// url of upload file
})
});}
create_blob(file, callback) {
var reader = new FileReader();
reader.onload = function () { callback(reader.result) };
reader.readAsDataURL(file);}我在控制台中发现了以下错误。
HttpErrorResponse {headers: HttpHeaders, status: 401, statusText: "Unauthorized", url: "https://api.cloudinary.com/v1_1/image/upload/", ok: false, …}发布于 2019-10-31 06:19:26
你犯了一个小错误,你错过了在你的帖子请求中添加cloud_name。您可以通过访问Cloudinary仪表板找到您的cloud_name。正确的代码如下
uploadImage(event) {
var that = this;
this.create_blob(event.srcElement.files[0], function (blob_string) {
that.http.post('https://api.cloudinary.com/v1_1/YOUR_CLOUD_NAME/image/upload/', { file: blob_string}).subscribe(res => {
// url of upload file
})注意:下面的方法是上传使用无符号方式,所以当您尝试下载图像时,它的url将启动为"http“而不是"https"
发布于 2019-10-19 22:39:52
根据您提供的代码,我可以看到以下几点:
X-Cld-Error的响应头,它将提供关于请求失败原因的更多信息。在这种情况下,我希望它返回cloud_name is disabled。当通过Cloudinary传递URL请求资源时,也会出现此标头,这将导致错误。例如,包含Invalid transformation parameter - ww.X-Cld-Error头,您使用的上传API端点不包括您的云名称。应该是https://api.cloudinary.com/v1_1/<cloud name>/image/uploadfile一起提供。Upload预设提供了一种方法来定义通常允许在使用签名时在上传调用中直接设置的上载参数。当不使用签名时,许多参数都无法指定,如果需要,应该在上传预置内配置。您可以在此了解更多信息,包括如何在文档的以下部分创建上载预置:https://cloudinary.com/documentation/upload_images#unsigned_upload。
https://stackoverflow.com/questions/58464638
复制相似问题