You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Ionic 4使用Uploadcare上传图片遇ERR_CONNECTION_REFUSED等报错求助

Hey there, let's tackle this Uploadcare + Ionic 4 image display error together—sounds like it's even popping up without any action now, which is tricky but let's break it down step by step.

常见排查与修复步骤

1. 验证Uploadcare基础配置

First things first, double-check your core Uploadcare setup:

  • Confirm your public key is correctly added to your Ionic project. For example, when initializing the Uploadcare widget:
    import * as uploadcare from 'uploadcare-widget';
    uploadcare.start({
      publicKey: 'YOUR_VALID_PUBLIC_KEY',
      // other config options
    });
    
  • Log into your Uploadcare dashboard to make sure your project isn't disabled, and you haven't hit any usage limits that might block resource requests.

2. Fix CORS & Ionic HTTP Restrictions

Ionic's WebView and development server often have CORS rules that can break Uploadcare requests:

  • In your Uploadcare dashboard, go to Project Settings > Security and add your app's domain (for local dev, it's usually http://localhost:8100; for production, use your live domain) to the Allowed Origins list.
  • If you're using Ionic's HttpClient, avoid adding custom headers that Uploadcare doesn't accept. For local development, you can set up a proxy in ionic.config.json to bypass CORS:
    "proxies": [
      {
        "path": "/uploadcare-api",
        "proxyUrl": "https://api.uploadcare.com"
      }
    ]
    
    Then use /uploadcare-api instead of the full API URL in your requests.

3. Check Image URL Formatting

Uploadcare relies on specific URL structures to serve images—mess this up, and you'll get errors:

  • Ensure you're using the full valid CDN URL, like https://ucarecdn.com/[IMAGE_UUID]/ or a processed version like https://ucarecdn.com/[IMAGE_UUID]/-/resize/400x400/.
  • Double-check for typos (like misspelling ucarecdn.com) or invalid UUIDs—if you're storing image references in a database, make sure they're saved correctly.

4. Troubleshoot Ionic WebView Compatibility

Ionic 4's WebView (especially older versions) can clash with Uploadcare's JS API:

  • Update your uploadcare-widget package to the latest compatible version (v3.x works well with Ionic 4).
  • Test on a physical device instead of just the browser—sometimes WebView behaves differently than desktop browsers. Also, confirm WebView allows HTTPS requests (all Uploadcare resources are served over HTTPS, so disabling this will break image loads).

5. Debug "No Action" Errors

Since the error pops up without any user action, focus on initialization or global code:

  • Check your page lifecycle hooks (like ngOnInit)—are you accidentally calling Uploadcare methods that reference a non-existent image UUID, or hitting an invalid API endpoint on page load?
  • Open your browser's dev tools (or Ionic DevApp's debug console) to get the exact error code:
    • 403: Permission issue (wrong public key or missing allowed origin)
    • 404: Invalid image UUID or URL
    • 500: Uploadcare server-side issue (try again later or reach out to their support)

6. Test a Minimal Working Example

If all else fails, build a stripped-down Ionic page to isolate the problem:

<ion-content class="ion-padding">
  <input type="hidden" role="uploadcare-uploader" data-public-key="YOUR_PUBLIC_KEY">
  <img id="display-image" src="" alt="Uploaded image" class="ion-margin-top">
</ion-content>
import { Component, OnInit } from '@angular/core';
import * as uploadcare from 'uploadcare-widget';

@Component({
  selector: 'app-upload-test',
  templateUrl: './upload-test.page.html',
  styleUrls: ['./upload-test.page.scss'],
})
export class UploadTestPage implements OnInit {

  constructor() { }

  ngOnInit() {
    uploadcare.start({ publicKey: 'YOUR_PUBLIC_KEY' });
    const uploader = uploadcare.Widget('[role=uploadcare-uploader]');
    
    uploader.onUploadComplete((imageInfo) => {
      document.getElementById('display-image').setAttribute('src', imageInfo.cdnUrl);
    });
  }

}

If this minimal example works, the issue is likely with other code in your project (like route guards, HTTP interceptors, or conflicting libraries) interfering with Uploadcare.

内容的提问来源于stack exchange,提问作者M. Mariscal

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.11 09:24:51