S3 bucket request with plus character in prefix

52 views
Skip to first unread message

Paul Mietz Egli

unread,
Nov 3, 2010, 1:22:27 PM11/3/10
to ASIHTTPRequest
I have buckets that are named with an ISO timestamp (i.e.
"2010-11-03T10:12:00-0700") and am listing the contents as follows:

ASIS3BucketRequest *listRequest = [ASIS3BucketRequest
requestWithBucket:@"my-bucket-name"];
[listRequest setPrefix:@"foo/2010-11-03T10:12:00-0700"];
[listRequest setDelimiter:@"/"];
[listRequest startSynchronous];

This works fine for the timestamp shown above, but list requests for
prefixes that have timestamps containing a plus character (for
example, "2010-20-03T10:12:00+0200") return no objects. The problem
lies in [ASIS3BucketRequest createQueryString] -- the call to
[NSString
stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding] does
not encode the plus symbol correctly, so S3 is treating it as a space
character in the URL. If I try to pre-encoding the plus to "%2B"
before I call setPrefix, the percent sign of "%2B" gets encoded in
createQueryString, so that doesn't work.

The workaround that I've found is to change createQueryString to
manually encode the plus signs as follows:

[queryParts addObject:[NSString stringWithFormat:@"prefix=%@",[[[self
prefix]
stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]
stringByReplacingOccurrencesOfString:@"+" withString:@"%2B"]]];

I'm not terribly happy with this, but I wanted to bring it up in case
anyone else ran into this issue.

p.

Ben Copsey

unread,
Nov 7, 2010, 7:36:30 AM11/7/10
to asihttp...@googlegroups.com
Hi Paul

ASIFormDataRequest has the encodeURL: method that should handle plus signs properly, perhaps I should start using this in ASIS3Request too. I'll add it to the to-do list.

Best,

Ben

Reply all
Reply to author
Forward
0 new messages