2017-11-28 2 views
0

Ionic 4.4.0とaws-sdk 2.157.0を使用する。私は私の地元のWebブラウザからS3バケットを作成しようとしていますが、次のコードを実行しようとすると、CORSの問題に実行しています、メソッドcreateBucketByCompanyKey():AWS SDKと組み合わせてIonicプロキシを使用する方法

import { Injectable } from '@angular/core'; 
import * as AWS from 'aws-sdk'; 

@Injectable() 
export class AwsProvider { 

    private accessKeyId:string = 'myAccessKey'; 
    private secretAccessKey:string = 'mySuperSecret'; 
    private region:string = 'us-east-1'; 

    constructor() { 
    AWS.config.update({accessKeyId: this.accessKeyId, secretAccessKey: this.secretAccessKey, region: this.region}); 
    } 

    createBucketByCompanyKey(companyKey){ 

    let s3 = new AWS.S3(); 
    let params = { 
     Bucket: companyKey, 
     CreateBucketConfiguration: { 
     LocationConstraint: this.region 
     } 
    }; 
    s3.createBucket(params, function(err, data) { 
     if (err) console.log(err, err.stack); // an error occurred 
     else  console.log(data);   // successful response 
    }); 
    } 
} 

これは私にエラーを与える

https://s3.amazonaws.com/-KwzdjmyrHiMBCqHH1ZCロードに失敗しました:応答 リクエストをプリフライトするとアクセス制御チェックを通過しません:いいえ 要求された リソースに 'Access-Control-Allow-Origin'ヘッダーが存在します。したがって、オリジン 'http://localhost:8100'は許可されません。 応答にはHTTPステータスコード403が付きました。

これは数時間のグーグルで私をthis post hereに導きました。私はプロキシを通してイオンを走らせる必要があるようです。私もhttp://localhost:8100に私の "パス"を変更しようとしましたが、私は残ったままです。

{ 
    "name": "MyApp", 
    "app_id": "", 
    "type": "ionic-angular", 
    "integrations": {}, 
    "proxies": [ 
    { 
     "path": "/", 
     "proxyUrl": "https://s3.amazonaws.com/" 
    } 
    ] 
} 

は、私はまた、CORSを無効download a Chrome extensionに自分を伝える記事に遭遇しましたが、それはどちらか動作しませんでした。

このプロキシをAWSのSDKで使用するための設定方法について教えてください。

答えて

0

プロキシを忘れます。 Macの場合、端末で次のように入力してCORSを無効にしてGoogle Chromeブラウザを開きます。

オープン-a Googleの\クローム--args --disable-ウェブセキュリティ--user-データ-dirの

this postの賛辞。

関連する問題