Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Allows user to post/put files to any location. #4

Merged
merged 1 commit into from

2 participants

@achainan

This fixes the issue that arose here:

#2 (comment)

Thanks @mattt

@mattt mattt merged commit 9d1274b into AFNetworking:master
@mattt

Really sorry for taking so long to merge this in—this is clearly a good thing to have, and I appreciate you submitting it. Thank you, @achainan.

@achainan

No problem, thanks for merging it in @mattt. Btw it was great listening to you at the NYC iOS Meetup.

@mattt

Likewise! Thanks again :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jun 22, 2012
This page is out of date. Refresh to see the latest.
Showing with 15 additions and 9 deletions.
  1. +2 −0  AFAmazonS3Client.h
  2. +13 −9 AFAmazonS3Client.m
View
2  AFAmazonS3Client.h
@@ -121,6 +121,7 @@ extern NSString * const kAFAmazonS3BaseURLString;
Adds an object to a bucket using forms.
*/
- (void)postObjectWithFile:(NSString *)path
+ destinationPath:(NSString *)destinationPath
parameters:(NSDictionary *)parameters
progress:(void (^)(NSInteger bytesWritten, long long totalBytesWritten, long long totalBytesExpectedToWrite))progress
success:(void (^)(id responseObject))success
@@ -130,6 +131,7 @@ extern NSString * const kAFAmazonS3BaseURLString;
Adds an object to a bucket for a user that has write access to the bucket. A success response indicates the object was successfully stored; if the object already exists, it will be overwritten.
*/
- (void)putObjectWithFile:(NSString *)path
+ destinationPath:(NSString *)destinationPath
parameters:(NSDictionary *)parameters
progress:(void (^)(NSInteger bytesWritten, long long totalBytesWritten, long long totalBytesExpectedToWrite))progress
success:(void (^)(id responseObject))success
View
22 AFAmazonS3Client.m
@@ -34,7 +34,8 @@ @interface AFAmazonS3Client ()
@property (readwrite, nonatomic, copy) NSString *secret;
- (void)setObjectWithMethod:(NSString *)method
- file:(NSString *)path
+ file:(NSString *)filePath
+ destinationPath:(NSString *)destinationPath
parameters:(NSDictionary *)parameters
progress:(void (^)(NSInteger bytesWritten, long long totalBytesWritten, long long totalBytesExpectedToWrite))progressBlock
success:(void (^)(id responseObject))success
@@ -76,7 +77,7 @@ - (NSURL *)baseURL {
if (_s3_baseURL && self.bucket) {
return [NSURL URLWithString:[NSString stringWithFormat:kAFAmazonS3BucketBaseURLFormatString, self.bucket]];
}
-
+
return _s3_baseURL;
}
@@ -197,21 +198,23 @@ - (void)getObjectWithPath:(NSString *)path
}
- (void)postObjectWithFile:(NSString *)path
+ destinationPath:(NSString *)destinationPath
parameters:(NSDictionary *)parameters
progress:(void (^)(NSInteger bytesWritten, long long totalBytesWritten, long long totalBytesExpectedToWrite))progress
success:(void (^)(id responseObject))success
failure:(void (^)(NSError *error))failure
{
- [self setObjectWithMethod:@"POST" file:path parameters:parameters progress:progress success:success failure:failure];
+ [self setObjectWithMethod:@"POST" file:path destinationPath:destinationPath parameters:parameters progress:progress success:success failure:failure];
}
- (void)putObjectWithFile:(NSString *)path
+ destinationPath:(NSString *)destinationPath
parameters:(NSDictionary *)parameters
progress:(void (^)(NSInteger bytesWritten, long long totalBytesWritten, long long totalBytesExpectedToWrite))progress
success:(void (^)(id responseObject))success
failure:(void (^)(NSError *error))failure
{
- [self setObjectWithMethod:@"PUT" file:path parameters:parameters progress:progress success:success failure:failure];
+ [self setObjectWithMethod:@"PUT" file:path destinationPath:destinationPath parameters:parameters progress:progress success:success failure:failure];
}
- (void)deleteObjectWithPath:(NSString *)path
@@ -222,13 +225,14 @@ - (void)deleteObjectWithPath:(NSString *)path
}
- (void)setObjectWithMethod:(NSString *)method
- file:(NSString *)path
- parameters:(NSDictionary *)parameters
+ file:(NSString *)filePath
+ destinationPath:(NSString *)destinationPath
+ parameters:(NSDictionary *)parameters
progress:(void (^)(NSInteger bytesWritten, long long totalBytesWritten, long long totalBytesExpectedToWrite))progress
success:(void (^)(id responseObject))success
failure:(void (^)(NSError *error))failure
{
- NSMutableURLRequest *fileRequest = [NSMutableURLRequest requestWithURL:[NSURL fileURLWithPath:path]];
+ NSMutableURLRequest *fileRequest = [NSMutableURLRequest requestWithURL:[NSURL fileURLWithPath:filePath]];
[fileRequest setCachePolicy:NSURLCacheStorageNotAllowed];
NSURLResponse *response = nil;
@@ -236,8 +240,8 @@ - (void)setObjectWithMethod:(NSString *)method
NSData *data = [NSURLConnection sendSynchronousRequest:fileRequest returningResponse:&response error:&error];
if (data && response) {
- NSMutableURLRequest *request = [self multipartFormRequestWithMethod:method path:path parameters:parameters constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
- [formData appendPartWithFileData:data name:@"file" fileName:[path lastPathComponent] mimeType:[response MIMEType]];
+ NSMutableURLRequest *request = [self multipartFormRequestWithMethod:method path:destinationPath parameters:parameters constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
+ [formData appendPartWithFileData:data name:@"file" fileName:[filePath lastPathComponent] mimeType:[response MIMEType]];
}];
AFHTTPRequestOperation *requestOperation = [self HTTPRequestOperationWithRequest:request success:^(AFHTTPRequestOperation *operation, id responseObject) {
Something went wrong with that request. Please try again.