S3 putObject使用aws-sdk失败(S3 putObject fails using aws-sdk)
它让我发疯,任何帮助都会非常感激!
为了在S3中设置我的桶我跟着http://www.cheynewallace.com/uploading-to-s3-with-angularjs/
关于这篇文章,我通过使用通配符扩展政策并提供更多权利来实现“改进”
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "s3:DeleteObject", "s3:DeleteObjectVersion", "s3:GetObject", "s3:GetObjectAcl", "s3:GetObjectTorrent", "s3:GetObjectVersion", "s3:GetObjectVersionAcl", "s3:GetObjectVersionTorrent", "s3:PutObject", "s3:PutObjectAcl", "s3:PutObjectVersionAcl" ], "Resource": [ "arn:aws:s3:::photos-eu/*" ] } ] }
并将<ExposeHeader> ETag </ ExposeHeader>添加到存储桶的Cors设置中
然后我使用aws-sdk的角度服务看起来像
/// <reference path="../../../typings/tsd.d.ts" /> module Services { export interface IS3UploadService { upload(imgName:string, imgData:string):ng.IPromise<{}>; } export class S3UploadService implements IS3UploadService { static $inject = ['$q']; private bucket:AWS.S3; constructor(private $q:ng.IQService) { var credentials = new AWS.Credentials("myAccessKeyId", "mySecretAccessKey"); AWS.config.update(credentials); AWS.config.region = "eu-west-1"; this.bucket = new AWS.S3({params: {Bucket: 'peterparker-photos-eu', maxRetries: 10, region: "eu-west-1"}}); } upload(imgName:string, imgData:string):ng.IPromise<{}> { var deferred = this.$q.defer(); var params:AWS.s3.PutObjectRequest = { Bucket: "peterparker-photos-eu", Key: imgName, Body: imgData, ContentType: "image/jpeg", ContentEncoding: "Base64" }; this.bucket.putObject(params, (err:any, data:any) => { if (err) { console.error("->" + JSON.stringify(err)); deferred.reject(err); } else { console.info(data); deferred.resolve(data); } }); return deferred.promise; } } } angular.module('App') .service('S3UploadService', Services.S3UploadService);
为了我的测试目的,我将imgData推入一个编码为Base64的img,类似“/ 9j / 4AAQSkZJRgABAgAAZABkA ....”(当然是用http://base64-image.de转换的有效图像)
结果,每次我尝试,我都有以下错误
{“line”:25,“column”:24996,“sourceURL”:“ http:// localhost:8100 / lib / aws-sdk / dist / aws-sdk.min.js ”,“message”:“请求我们计算的签名与您提供的签名不符。检查您的密钥和签名方法。“,”code“:”SignatureDoesNotMatch“,”region“:null,”time“:”2016-06-08T15:12:09.945Z“ “的requestId”:空 “的StatusCode”:403, “重试”:假的, “retryDelay”:60.59883770067245}
玩得很尽兴...
更新标题:
General Request URL:https://peterparker-photos-eu.s3-eu-west-1.amazonaws.com/1465408512724.jpg Request Method:PUT Status Code:403 Forbidden Remote Address:54.231.131.16:443 Response headers Access-Control-Allow-Methods:HEAD, GET, PUT, POST, DELETE Access-Control-Allow-Origin:* Access-Control-Expose-Headers:ETag, x-amz-meta-custom-header Connection:close Content-Type:application/xml Date:Wed, 08 Jun 2016 17:55:20 GMT Server:AmazonS3 Transfer-Encoding:chunked Vary:Origin, Access-Control-Request-Headers, Access-Control-Request- Method x-amz-id-... x-amz-request-id:... Request Headers Accept:*/* Accept-Encoding:gzip, deflate, sdch, br Accept-Language:fr-FR,fr;q=0.8,en-US;q=0.6,en;q=0.4,de;q=0.2 Authorization:AWS ... Connection:keep-alive Content-Encoding:Base64 Content-Length:38780 Content-MD5:... Content-Type:image/jpeg; charset=UTF-8 Host:peterparker-photos-eu.s3-eu-west-1.amazonaws.com Origin:http://localhost:8100 Referer:http://localhost:8100/?ionicplatform=ios User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.79 Safari/537.36 X-Amz-Date:Wed, 08 Jun 2016 17:55:20 GMT X-Amz-User-Agent:aws-sdk-js/2.3.18 Request payload Img base64 code
更新
即使尝试上传非Base64内容,它也会以相同的错误结束
var paramsHtml:AWS.s3.PutObjectRequest = { Bucket: "peterparker-photos-eu", Key: "HelloWorld.html", Body: "The Body", ContentType: "text/html" };
更新#2
我移动到我的节点js服务器生成的带有签名URL的解决方案,如下面的解决方案所述,仍然得到与结果相同的错误...但我至少尝试;)
It's driving me crazy, any help would be much appreciated!
To set up my bucket in S3 I followed http://www.cheynewallace.com/uploading-to-s3-with-angularjs/
Regarding this post I made following "improvements" by extended the policy with a wildcard and giving more rights
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "s3:DeleteObject", "s3:DeleteObjectVersion", "s3:GetObject", "s3:GetObjectAcl", "s3:GetObjectTorrent", "s3:GetObjectVersion", "s3:GetObjectVersionAcl", "s3:GetObjectVersionTorrent", "s3:PutObject", "s3:PutObjectAcl", "s3:PutObjectVersionAcl" ], "Resource": [ "arn:aws:s3:::photos-eu/*" ] } ] }
and added < ExposeHeader>ETag< /ExposeHeader > to the Cors settings of the bucket
Then my angular service using the aws-sdk look like
/// <reference path="../../../typings/tsd.d.ts" /> module Services { export interface IS3UploadService { upload(imgName:string, imgData:string):ng.IPromise<{}>; } export class S3UploadService implements IS3UploadService { static $inject = ['$q']; private bucket:AWS.S3; constructor(private $q:ng.IQService) { var credentials = new AWS.Credentials("myAccessKeyId", "mySecretAccessKey"); AWS.config.update(credentials); AWS.config.region = "eu-west-1"; this.bucket = new AWS.S3({params: {Bucket: 'peterparker-photos-eu', maxRetries: 10, region: "eu-west-1"}}); } upload(imgName:string, imgData:string):ng.IPromise<{}> { var deferred = this.$q.defer(); var params:AWS.s3.PutObjectRequest = { Bucket: "peterparker-photos-eu", Key: imgName, Body: imgData, ContentType: "image/jpeg", ContentEncoding: "Base64" }; this.bucket.putObject(params, (err:any, data:any) => { if (err) { console.error("->" + JSON.stringify(err)); deferred.reject(err); } else { console.info(data); deferred.resolve(data); } }); return deferred.promise; } } } angular.module('App') .service('S3UploadService', Services.S3UploadService);
For my test purpose, I push in the imgData an img encoded as Base64, something like "/9j/4AAQSkZJRgABAgAAZABkA...." (of course a valid image converted with http://base64-image.de)
And as result, each time I try, I've got following error
{"line":25,"column":24996,"sourceURL":"http://localhost:8100/lib/aws-sdk/dist/aws-sdk.min.js","message":"The request signature we calculated does not match the signature you provided. Check your key and signing method.","code":"SignatureDoesNotMatch","region":null,"time":"2016-06-08T15:12:09.945Z","requestId":null,"statusCode":403,"retryable":false,"retryDelay":60.59883770067245}
So much fun...
Update headers:
General Request URL:https://peterparker-photos-eu.s3-eu-west-1.amazonaws.com/1465408512724.jpg Request Method:PUT Status Code:403 Forbidden Remote Address:54.231.131.16:443 Response headers Access-Control-Allow-Methods:HEAD, GET, PUT, POST, DELETE Access-Control-Allow-Origin:* Access-Control-Expose-Headers:ETag, x-amz-meta-custom-header Connection:close Content-Type:application/xml Date:Wed, 08 Jun 2016 17:55:20 GMT Server:AmazonS3 Transfer-Encoding:chunked Vary:Origin, Access-Control-Request-Headers, Access-Control-Request- Method x-amz-id-... x-amz-request-id:... Request Headers Accept:*/* Accept-Encoding:gzip, deflate, sdch, br Accept-Language:fr-FR,fr;q=0.8,en-US;q=0.6,en;q=0.4,de;q=0.2 Authorization:AWS ... Connection:keep-alive Content-Encoding:Base64 Content-Length:38780 Content-MD5:... Content-Type:image/jpeg; charset=UTF-8 Host:peterparker-photos-eu.s3-eu-west-1.amazonaws.com Origin:http://localhost:8100 Referer:http://localhost:8100/?ionicplatform=ios User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.79 Safari/537.36 X-Amz-Date:Wed, 08 Jun 2016 17:55:20 GMT X-Amz-User-Agent:aws-sdk-js/2.3.18 Request payload Img base64 code
Update
Even by trying to upload a non Base64 content it finish with the same error
var paramsHtml:AWS.s3.PutObjectRequest = { Bucket: "peterparker-photos-eu", Key: "HelloWorld.html", Body: "The Body", ContentType: "text/html" };
Update #2
I moved to a solution with a signed URL generated by my node js server as described in following solution, still got the same error as result...but I least I try ;)
upload file from angularjs directly to amazon s3 using signed url
原文:https://stackoverflow.com/questions/37706775
最满意答案
我怀疑你的麻烦是由于初始化函数。
LoadContent
由Initialize
调用。 有两件事你需要检查:
- 在调用
base.Initialize()
之前,验证您是否在Game.cs中创建并添加了可绘制的游戏组件。 在上面的代码中,您正在创建并添加Game.cs的LoadContent
函数中的组件,该函数在Initialize
之后发生。验证
Editor
类中的Initialize
函数是否正在调用基本的Initialize
函数:public override void Initialize() { base.Initialize(); }
查看Nick Gravelyn撰写的这篇博客文章 ,了解更多信息。 Nick特别与你的问题相关,在他的文章中写道:
- 首先你会得到一个Initialize调用。 这是您通常为您的游戏*放置非图形化初始化代码的地方。 你还需要确保你调用base.Initialize()。 当你这样做时,游戏会做一些事情:
- 在Components集合中的每个GameComponent上调用Initialize。
- 创建GraphicsDevice。
- 在游戏中调用LoadContent。
- 为Components集合中的每个DrawableGameComponent调用LoadContent。
I suspect your trouble is due to the Initialize function.
LoadContent
is called byInitialize
. There are two things you need to check for:
- Verify that you are creating and adding your drawable game component in Game.cs before
base.Initialize()
is called. In the code above, you are creating and adding the component in theLoadContent
function of Game.cs, which occurs afterInitialize
.Verify that the
Initialize
function in yourEditor
class is calling the baseInitialize
function:public override void Initialize() { base.Initialize(); }
Check out this blog post by Nick Gravelyn for more information. Particularly relevant to your question, in his post, Nick writes that:
- First you’ll get a call to Initialize. This is where you generally put non-graphical initialization code for your game*. You also need to make sure you call base.Initialize(). When you do, the game does a few things:
- Calls Initialize on each GameComponent in the Components collection.
- Creates the GraphicsDevice.
- Calls LoadContent on the game.
- Calls LoadContent for each DrawableGameComponent in the Components collection.
相关问答
更多-
问题出在您的方法上。 你不需要返回,只需运行你想要的动作,如下所示: methods: { addComponent: function(){ this.components++; } } The problem is with your method. You don't need to return, just run the action you want, like this: methods: { addComponent: function(){ this.comp ...
-
我怀疑你的麻烦是由于初始化函数。 LoadContent由Initialize调用。 有两件事你需要检查: 在调用base.Initialize()之前,验证您是否在Game.cs中创建并添加了可绘制的游戏组件。 在上面的代码中,您正在创建并添加Game.cs的LoadContent函数中的组件,该函数在Initialize之后发生。 验证Editor类中的Initialize函数是否正在调用基本的Initialize函数: public override void Initialize() { b ...
-
使用vSphere客户端,您可以连接到vCenter或直接连接到主机。 当然,如果将主机添加到vCenter,您应该只将它连接到vCenter,因为vCenter应该知道主机上所做的任何更改。 在紧急情况下(例如,vCenter已关闭),应直接连接到主机。 Using vSphere client you can connect to vCenter or directly to host. Of course if host is added to vCenter you should to connec ...
-
好的,这里是plunker: http ://plnkr.co/edit/qMnXG7oxF3SdTptKHUen?p =preview stackoverflow上有很多关于这个问题的答案,你不是第一次发布这个问题.. 您将首先为您的应用程序创建共享服务 import {Subject} from 'rxjs/Subject'; @Injectable() export class MyService { public invokeEvent:Subject
= new Subjec ... -
为避免覆盖引导功能,应添加属性renaming: false $('.navbar-brand').sidr({ name: 'sidr-left', side: 'left', source: '.nav-collapse', renaming: false//<-- }); 的jsfiddle To avoid overriding the bootstrap functionality the property renaming: false should be a ...
-
正如异常所述: “NullReferenceError”表示当您尝试调用LoadContent()时g为null。 我有一种感觉,你需要检查gameObjects的一致性。 希望这可以帮助! As the exception states : "NullReferenceError" means that g is null when you try to invoke LoadContent(). I have a feeling that you need to check gameObjects fo ...
-
您需要将解释的组件名称解析为:is=""组件,按以下方式定义它们应该起作用: import GroupsGrid from './../../components/groups' import RolesGrid from './../../components/roles' import MainTabs from './../../components/main-tabs.vue' // <-- this component will be render other components da ...
-
在JavaFX2中的loadContent之后,“提交”按钮单击不起作用(Submit button click does not work after loadContent in JavaFX2)[2022-08-04]
按下提交按钮时运行的HTML / Javascript代码是什么? 相关表格的action属性是什么? 我怀疑由于webEngine.loadContent()调用,页面不知道提交表单的位置,这就是它无法正常工作的原因。 通过正常加载页面并使用userStyleSheetLocation属性手动设置样式表( ref ),可以纠正样式问题。 我建议您使用userStyleSheetLocation进行一些实验。 The custom font loading issue is resolved with jd ... -
使用jquery ajax上传组件的tapestry在IE中不起作用(tapestry with jquery ajax upload component does not work in IE)[2024-01-17]
这是预期和正常的。 浏览器不提供在IE 9或更早版本中确定文件大小客户端的功能。 This is expected and normal. The browser does not provide the ability to determine file size client side in IE 9 or older. -
您需要在主Vue实例之前声明组件: Vue.component('child',{ props:['message'], template:"{{message}}" }) new Vue({ el:'#app' }); 这是JSFiddle: https ://jsfiddle.net/Lxeb7gmo/ You component needs to be declared before your main Vue instance: Vue.component( ...