Skip to content
This repository has been archived by the owner on Jan 17, 2023. It is now read-only.

Commit

Permalink
Conditionally construct multipart form request depending on HTTP method
Browse files Browse the repository at this point in the history
  • Loading branch information
mattt committed Nov 29, 2014
1 parent bf540a5 commit cc21e90
Showing 1 changed file with 20 additions and 14 deletions.
34 changes: 20 additions & 14 deletions AFAmazonS3Client/AFAmazonS3Manager.m
Original file line number Diff line number Diff line change
Expand Up @@ -237,21 +237,27 @@ - (void)setObjectWithMethod:(NSString *)method

destinationPath = [destinationPath stringByReplacingOccurrencesOfString:@" " withString:@"+"];

NSError *requestError = nil;
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"];
NSMutableURLRequest *request = nil;
if ([method compare:@"POST" options:NSCaseInsensitiveSearch] == NSOrderedSame) {
NSError *requestError = nil;
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:&requestError];

if (requestError || !request) {
if (failure) {
failure(requestError);
}

return;
}

[formData appendPartWithFileData:data name:@"file" fileName:[filePath lastPathComponent] mimeType:[response MIMEType]];
} error:&requestError];

if (requestError || !request) {
if (failure) {
failure(requestError);
}

return;
} else {
request = [self.requestSerializer requestWithMethod:method URLString:[[self.baseURL URLByAppendingPathComponent:destinationPath] absoluteString] parameters:parameters error:nil];
request.HTTPBody = data;
}

AFHTTPRequestOperation *requestOperation = [self HTTPRequestOperationWithRequest:request success:^(__unused AFHTTPRequestOperation *operation, id responseObject) {
Expand Down

2 comments on commit cc21e90

@jerryhalstead
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know if this fix was meant to solve a problem I'm having, but when I use putObjectWithFile to upload a file over 128MB something starts chewing up 128MB chunks of memory until the app crashes. This happens before the first call to progress. Smaller uploads are fine.

screen shot 2015-01-22 at 12 27 46 pm

@jerryhalstead
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually the trigger doesn't seem to be 128MB, but somewhere over 100MB.

Please sign in to comment.