Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #4 from achainan/master

Allows user to post/put files to any location.
  • Loading branch information...
commit 9d1274b4446a91fd9e31df228a7a35d946cc4e32 2 parents 2f96fff + 6ccf773
@mattt mattt authored
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) {
Please sign in to comment.
Something went wrong with that request. Please try again.