-
Notifications
You must be signed in to change notification settings - Fork 3
Change used of NSString* to NSURL* in the public API #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 2.2
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| .DS_Store |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,6 +26,7 @@ | |
|
|
||
| @interface AFAmazonS3Manager () | ||
| @property (readwrite, nonatomic, strong) NSURL *baseURL; | ||
| @property (readwrite, nonatomic) NSTimeInterval sendTimeout; | ||
| @end | ||
|
|
||
| @implementation AFAmazonS3Manager | ||
|
|
@@ -39,6 +40,7 @@ - (instancetype)initWithBaseURL:(NSURL *)url { | |
|
|
||
| self.requestSerializer = [AFAmazonS3RequestSerializer serializer]; | ||
| self.responseSerializer = [AFXMLParserResponseSerializer serializer]; | ||
| self.sendTimeout = 30; | ||
|
|
||
| return self; | ||
| } | ||
|
|
@@ -52,7 +54,6 @@ - (id)initWithAccessKeyID:(NSString *)accessKey | |
| } | ||
|
|
||
| [self.requestSerializer setAccessKeyID:accessKey secret:secret]; | ||
|
|
||
| return self; | ||
| } | ||
|
|
||
|
|
@@ -184,7 +185,7 @@ - (void)getObjectWithPath:(NSString *)path | |
| [self.operationQueue addOperation:requestOperation]; | ||
| } | ||
|
|
||
| - (void)postObjectWithFile:(NSString *)path | ||
| - (void)postObjectWithFile:(NSURL *)path | ||
| destinationPath:(NSString *)destinationPath | ||
| parameters:(NSDictionary *)parameters | ||
| progress:(void (^)(NSUInteger bytesWritten, long long totalBytesWritten, long long totalBytesExpectedToWrite))progress | ||
|
|
@@ -194,7 +195,7 @@ - (void)postObjectWithFile:(NSString *)path | |
| [self setObjectWithMethod:@"POST" file:path destinationPath:destinationPath parameters:parameters progress:progress success:success failure:failure]; | ||
| } | ||
|
|
||
| - (void)putObjectWithFile:(NSString *)path | ||
| - (void)putObjectWithFile:(NSURL *)path | ||
| destinationPath:(NSString *)destinationPath | ||
| parameters:(NSDictionary *)parameters | ||
| progress:(void (^)(NSUInteger bytesWritten, long long totalBytesWritten, long long totalBytesExpectedToWrite))progress | ||
|
|
@@ -212,49 +213,44 @@ - (void)deleteObjectWithPath:(NSString *)path | |
| } | ||
|
|
||
| - (void)setObjectWithMethod:(NSString *)method | ||
| file:(NSString *)filePath | ||
| file:(NSURL *)fileUrl | ||
| destinationPath:(NSString *)destinationPath | ||
| parameters:(NSDictionary *)parameters | ||
| progress:(void (^)(NSUInteger bytesWritten, long long totalBytesWritten, long long totalBytesExpectedToWrite))progress | ||
| success:(void (^)(id responseObject))success | ||
| failure:(void (^)(NSError *error))failure | ||
| { | ||
| NSMutableURLRequest *fileRequest = [NSMutableURLRequest requestWithURL:[NSURL fileURLWithPath:filePath]]; | ||
| [fileRequest setCachePolicy:NSURLCacheStorageNotAllowed]; | ||
|
|
||
| NSURLResponse *response = nil; | ||
| NSError *fileError = nil; | ||
| NSData *data = [NSURLConnection sendSynchronousRequest:fileRequest returningResponse:&response error:&fileError]; | ||
|
|
||
| if (data && response) { | ||
| NSMutableURLRequest *request = [self.requestSerializer multipartFormRequestWithMethod:method URLString:[[self.baseURL URLByAppendingPathComponent:destinationPath] absoluteString] parameters:parameters constructingBodyWithBlock:^(id <AFMultipartFormData> formData) { | ||
| if (![parameters valueForKey:@"key"]) { | ||
| [formData appendPartWithFormData:[[filePath lastPathComponent] dataUsingEncoding:NSUTF8StringEncoding] name:@"key"]; | ||
| } | ||
| [formData appendPartWithFileData:data name:@"file" fileName:[filePath lastPathComponent] mimeType:[response MIMEType]]; | ||
| } error:nil]; | ||
|
|
||
| // NSURL *temporaryFileURL = [NSURL fileURLWithPath:[NSTemporaryDirectory() stringByAppendingPathComponent:[[NSUUID UUID] UUIDString]]]; | ||
| // request = [self.requestSerializer requestWithMultipartFormRequest:request writingStreamContentsToFile:temporaryFileURL completionHandler:^(NSError *error) { | ||
| // if (!error) { | ||
| // [request setHTTPBody:[NSData dataWithContentsOfFile:[temporaryFileURL absoluteString]]]; | ||
| // } | ||
| // }]; | ||
|
|
||
| AFHTTPRequestOperation *requestOperation = [self HTTPRequestOperationWithRequest:request success:^(__unused AFHTTPRequestOperation *operation, id responseObject) { | ||
| if (success) { | ||
| success(responseObject); | ||
| } | ||
| } failure:^(__unused AFHTTPRequestOperation *operation, NSError *error) { | ||
| if (failure) { | ||
| failure(error); | ||
| } | ||
| }]; | ||
|
|
||
| [requestOperation setUploadProgressBlock:progress]; | ||
|
|
||
| [self.operationQueue addOperation:requestOperation]; | ||
|
|
||
| NSError* requestError = nil; | ||
| NSMutableURLRequest *request = [self.requestSerializer requestWithMethod:method | ||
| URLString:[[self.baseURL URLByAppendingPathComponent:destinationPath] absoluteString] | ||
| parameters:parameters | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I found that this call to |
||
| error:&requestError]; | ||
|
|
||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If the user passes a path does not exist locally here, then |
||
| if (requestError && failure) { | ||
| failure(requestError); | ||
| return; | ||
| } | ||
|
|
||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. After the uploads completed successfully, the contents on S3 were multi-part MIME documents, rather than just the content of the file that I wanted to uploaded. I was uploading images, and there was a few lines of plain test at the start of each image referring to |
||
| [request setHTTPBody:[NSData dataWithContentsOfURL:fileUrl]]; | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| [request setTimeoutInterval:self.sendTimeout]; | ||
|
|
||
| AFHTTPRequestOperation *requestOperation = [self HTTPRequestOperationWithRequest:request success:^(__unused AFHTTPRequestOperation *operation, id responseObject) { | ||
| if (success) { | ||
| success(responseObject); | ||
| } | ||
| } failure:^(__unused AFHTTPRequestOperation *operation, NSError *error) { | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nuked commented out code. |
||
| if (failure) { | ||
| NSLog(@"Operation: %@", operation); | ||
| NSLog(@"Response String: %@", operation.responseString); | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When an S3 operation failed, the response contains an XML description of the problem, but I didn't see a way to get this data from the NSError directly. |
||
| failure(error); | ||
| return; | ||
| } | ||
| }]; | ||
|
|
||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If the call to [requestOperation setUploadProgressBlock:progress];
[self.operationQueue addOperation:requestOperation];still take place, with an invalid |
||
| [requestOperation setUploadProgressBlock:progress]; | ||
|
|
||
| [self.operationQueue addOperation:requestOperation]; | ||
| } | ||
|
|
||
| #pragma mark - NSKeyValueObserving | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added this while debugging problems I was having with operations seemingly starting but never completing. Some of these problems were caused by the code not calling the
failureblock in all failure cases, so it appeared like an upload had commenced when it had not, for example.