0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Angular2でGCSのSignedURLのファイル(Blob)を取得する

Posted at

Angular2でGCSのSignedURLのファイル(Blob)を取得する

  • SignedUrlは正しいし、CORSは*。
  private fetchUrlAsBlob = (url: string): Observable<Blob> => {
    const options = {
      responseType: ResponseContentType.Blob,
      // headers: new Headers({'Content-Type': 'application/x-www-form-urlencoded'}),
    };
    return this.http.get(url, options).map((res) => {
      return res.blob();
    });
  }

Content-Typeをつけると403でSignatureDoesNotMatchというエラーが帰って来て困った

response
<?xml version='1.0' encoding='UTF-8'?><Error><Code>SignatureDoesNotMatch</Code><Message>The request signature we calculated does not match the signature you provided. Check your Google secret key and signing method.</Message><StringToSign>GET

application/x-www-form-urlencoded
1521814129
/my-bucket/foo%2Fbar%2Fimages%2Fapple.jpg</StringToSign></Error>

StringToSignのタグの中身を見ると、文字列にContent-typeで指定したヘッダー値が含まれている。
署名時に指定したものと異なるので当然シグネチャが違うんでしょうね。
Headerも含めた文字列が署名対象ということかな。
まあ、妥当といえば妥当なきもする。

ありがとう

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?