由于google doc viewer api,我尝试在iframe中显示存储在S3存储桶中的.doc文件。
我已经做了一些研究并找到this,我试图在这里申请:
var encodedUrl = encodeURIComponent("http://myAPI.com/1d293950-67b2-11e7-8530-318c83fb9802/example.docx?X-Amz-Algorithm=AWS4-HMAC-SHA256%26X-Amz-Credential=GNRO0BLDYAJP1FU7ALIS%2F20170717%2Fus-east-1%2Fs3%2Faws4_request%26X-Amz-Date=20170717T145429Z%26X-Amz-Expires=600%26X-Amz-SignedHeaders=host%26X-Amz-Signature=ee556c5c92427bb38265507218a701660936bc2774ecc919648bb2d780a2619f");
$scope.selectedSource = $sce.trustAsResourceUrl(
"http://docs.google.com/gview?url=" + encodedUrl + "&embedded=true"
);
iframe看起来像:
<iframe ng-src="{{selectedSource}}" frameborder="no" style="width:100%;height:100%"></iframe>
但我仍然从iframe中的查看器中获得“无预览可用”,任何想法为什么?
我指定签名的网址(未编码)在我将其粘贴到浏览器中时有效,因此我拥有所需的所有权利。
答案 0 :(得分:0)
专门针对Amazon s3签名网址检查解决方案。基本上它用于使用Google Docs Viewer查看私人文档
Google Docs Viewer with Amazon S3 Private Documents and Presigned URLs
答案 1 :(得分:0)
Amazon S3 Presigned URL包含查询字符串参数,因此它包含“?”和“&”混淆外部网址。
因此,您必须先对S3预签名URL进行编码,然后再将其传递给Google Doc Viewer。
赞:
var encodedUrl = encodeURIComponent(presigned_url);
var iFrameUrl = 'https://docs.google.com/gview?url=' + encodedUrl;
OR(使用S3 .NET Core API)
using (AmazonS3Client S3Client = new AmazonS3Client(accKey, secKey, new AmazonS3Config() { ServiceURL = serviceUrl }))
{
GetPreSignedUrlRequest getPreSignedUrl = new GetPreSignedUrlRequest
{
BucketName = s3BucketName,
Key = fileName,
Expires = DateTime.Now.AddMinutes(30)
};
encoded_SignedUrl = WebUtility.UrlEncode(S3Client.GetPreSignedURL(getPreSignedUrl));
}