Permalink
Browse files

added a destination path parameter to POST and PUT functions

  • Loading branch information...
Ajay Chainani
Ajay Chainani committed Jun 22, 2012
1 parent 2f96fff commit 6ccf7736a5528e839efc25a7c7854ed1420a117a
Showing with 15 additions and 9 deletions.
  1. +2 −0 AFAmazonS3Client.h
  2. +13 −9 AFAmazonS3Client.m
View
@@ -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
@@ -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,22 +225,23 @@ - (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;
NSError *error = nil;
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) {

0 comments on commit 6ccf773

Please sign in to comment.