Copy link to clipboard
Copied
Hi All,
I'm trying to pass urlrequest binding with "Date", "Authorization" to amazon s3 from flex 4.5 web application. However it's failed to connect and throws error as,
Error #2096: The HTTP request header Date cannot be set via ActionScript.
So, please tell me what i need to use or which flash player supports to add "Date" in header request.
Sory for the late reply. I have used presigned url to download file from s3.
Copy link to clipboard
Copied
are you using a query string appended to your http request? if so, copy and paste the request.
Copy link to clipboard
Copied
I'm have taken code from http://as3awss3lib.googlecode.com/svn/trunk to upload files into amazon s3 using flex web app.
Below is the code for that,
private function getURLRequest(method:String, resource:String, contentType:String = null, hash:String = null, secure:Boolean = true):URLRequest
{
var protocol:String = (secure) ? "https" : "http";
var req:URLRequest = new URLRequest(protocol + "://" + AMAZON_ENDPOINT + resource);
/*req.cacheResponse = false;
req.useCache = false;*/
req.method = method;
var dateString:String = getDateString(new Date());
var dateHeader:URLRequestHeader = new URLRequestHeader("Date", dateString);
var authHeader:URLRequestHeader = new URLRequestHeader("Authorization", getAuthenticationHeader(method, dateString, resource, contentType, hash));
req.requestHeaders.push(dateHeader);
req.requestHeaders.push(authHeader);
return req;
}
private function getAuthenticationHeader(verb:String,
dateString:String,
resource:String,
contentType:String = null,
hash:String = null):String
{
return ("AWS " + this.accessKey + ":" + getAuthenticationString(verb, dateString, resource, contentType, hash));
}
private function getAuthenticationString(verb:String,
dateString:String,
resource:String,
contentType:String = null,
hash:String = null):String
{
var toSign:String = verb + "\n";
toSign += (hash != null) ? hash + "\n" : "\n";
toSign += (contentType != null) ? contentType + "\n" : "\n";
toSign += dateString + "\n" + resource;
var toSignBytes:ByteArray = new ByteArray();
toSignBytes.writeUTFBytes(toSign);
var hmacBytes:ByteArray = hmac.compute(secretAccessKeyBytes, toSignBytes);
return Base64.encodeByteArray(hmacBytes);
}
Copy link to clipboard
Copied
Please someone guide me, possible way to acheive.
Copy link to clipboard
Copied
where's getDateString?
Copy link to clipboard
Copied
private function getDateString(d:Date):String
{
var dd:Date = new Date(d.getUTCFullYear(), d.getUTCMonth(), d.getUTCDate(), d.getUTCHours(), d.getUTCMinutes(), d.getUTCSeconds(), d.getUTCMilliseconds());
var ds:String = dateFormatter.format(dd);
return ds + " GMT";
}
Copy link to clipboard
Copied
escape that return.
and make sure your datetimeformatter has the correct params. i believe DateTimeFormatter(LocaleID.DEFAULT, DateTimeStyle.LONG, DateTimeStyle.NONE) should work.
Copy link to clipboard
Copied
Let me try it.
Copy link to clipboard
Copied
use:
private function getDateString(d:Date):String
{
/*var dd:Date = new Date(d.getUTCFullYear(), d.getUTCMonth(), d.getUTCDate(), d.getUTCHours(), d.getUTCMinutes(), d.getUTCSeconds(), d.getUTCMilliseconds());
var ds:String = dateFormatter.format(dd);
return ds + " GMT";*/
var df:DateTimeFormatter = new DateTimeFormatter(LocaleID.DEFAULT, DateTimeStyle.LONG, DateTimeStyle.NONE);
var sd:String = df.format(d);
return escape(sd);
}
p.s. if you see an error message click "permit debugging" and paste the entire error message and indicate the first listed problematic line of code in from the error message.
Copy link to clipboard
Copied
Could see my previous post saying where i'm getting error. "Error #2007: Parameter type must be non-null.". Sory to troble you. Added escape(shortDate) as per your suggestions.
Message was edited by: grace-glory
Copy link to clipboard
Copied
your code is difficult to read but it doesn't appear that error message is related to the discussion in this thread.
in any case, if you want help with that click "permit debugging" and paste the entire error message and indicate the first listed problematic line of code in from the error message.
Copy link to clipboard
Copied
Very sory, Error is coming before date.
Copy link to clipboard
Copied
Please take reference of my previous post. Getting error in below method,
AWSS3.as - listObjects(...) - getURLStream() - throws as "Error #2007: Parameter type must be non-null.". Same code is working perfectly in AIR 2.6 and flash builder 4.5.
I want to do same in flash builder 4.5 using web.
Copy link to clipboard
Copied
You cannot use Date and Authorization headers in Flash Player.
Adobe clearly states it in the docs: http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/URLRequestHeader.html
In Flash Player and in Adobe AIR content outside of the application security sandbox, the following request headers cannot be used, and the restricted terms are not case-sensitive (for example,
Get,get, andGETare all not allowed). Also, hyphenated terms apply if an underscore character is used (for example, bothContent-LengthandContent_Lengthare not allowed):
Accept-Charset,Accept-Encoding,Accept-Ranges,Age,Allow,Allowed,Authorization,Charge-To,Connect,Connection,Content-Length,Content-Location,Content-Range,Cookie,Date,Delete,ETag,Expect,Get,Head,Host,If-Modified-Since,Keep-Alive,Last-Modified,Location,Max-Forwards,Options,Origin,Post,Proxy-Authenticate,Proxy-Authorization,Proxy-Connection,Public,Put,Range,Referer,Request-Range,Retry-After,Server,TE,Trace,Trailer,Transfer-Encoding,Upgrade,URI,User-Agent,Vary,Via,Warning,WWW-Authenticate,x-flash-version.
And there is no workaround.
Copy link to clipboard
Copied
Thanks, I have achieved different way.
Copy link to clipboard
Copied
Caan you explain how you resolve?
Copy link to clipboard
Copied
Sory for the late reply. I have used presigned url to download file from s3.
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more