Created
February 27, 2014 17:13
-
-
Save brunofarache/9254542 to your computer and use it in GitHub Desktop.
Uploading binaries with Liferay JSONWS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
+ (void)upload:(NSData *)data folderId:(long)folderId | |
title:(NSString *)title mimeType:(NSString *)mimeType | |
requestDelegate:(id)requestDelegate | |
progressDelegate:(id)progressDelegate { | |
BOOL addGroupPermissions = | |
[self getAddGroupPermissions:[PrefsUtil getGroupType]]; | |
BOOL addGuestPermissions = | |
[self getAddGuestPermissions:[PrefsUtil getGroupType]]; | |
NSDictionary *parameters = @{ | |
@"repositoryId": [PrefsUtil getGroupId], | |
@"folderId": [NSNumber numberWithLong:folderId], | |
@"sourceFileName": EMPTY, | |
@"mimeType": mimeType, | |
@"title": title, | |
@"description": EMPTY, | |
@"changeLog": EMPTY, | |
@"serviceContext.addGroupPermissions": @(addGroupPermissions), | |
@"serviceContext.addGuestPermissions": @(addGuestPermissions) | |
}; | |
NSString *command = [self getCommand:@"add-file-entry"]; | |
AsyncRequest *request = | |
[HttpClient getUploadAsyncRequest:command data:data | |
parameters:parameters]; | |
[progressDelegate setMaxSize:[data length]]; | |
[request setTag:AddEntryRequest]; | |
[request setDelegate:requestDelegate]; | |
[request setProgressDelegate:progressDelegate]; | |
[request start]; | |
} | |
+ (AsyncRequest *)getUploadAsyncRequest:(NSString *)command data:(NSData *)data | |
parameters:(NSDictionary *)parameters { | |
HttpClient *client = [self getClient]; | |
void (^body)(id<AFMultipartFormData>) = | |
^(id<AFMultipartFormData> form) { | |
NSString *title = [parameters objectForKey:@"title"]; | |
NSString *mimeType = [parameters objectForKey:@"mimeType"]; | |
[form appendPartWithFileData:data name:@"file" fileName:title | |
mimeType:mimeType]; | |
}; | |
NSString *path = [HttpUtil getPath:NO]; | |
NSString *URL = [NSString stringWithFormat:@"%@jsonws%@", path, command]; | |
NSMutableURLRequest *request = | |
[client multipartFormRequestWithMethod:POST path:URL | |
parameters:parameters constructingBodyWithBlock:body]; | |
return [[AsyncRequest alloc] initWithRequest:request]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment