- (void)initWithData:(NSData *)data mimeType:(NSString
*)mimeType - Creates an SkyVaultContentFile instance, which is a
file in the temporary directory. The parameter data is the content for
the file to be created, and mimeType the specified mime
type.
Parameters
- (NSData *) data
- The file content.
- (NSString *) mimeType
- The mime type of the content.
Returns
(void)
Example
/**
uploadPhoto: uses the SkyVaultDocumentFolderService to upload an image using the method createDocumentWithName method
*/
- (void)uploadPhotoWithName:(NSString *)name description:(NSString *)description tags:(NSArray *)tags
{
self.progressView.hidden = NO;
[self.progressView setProgress:0.0];
NSMutableDictionary *properties = [NSMutableDictionary dictionaryWithObject:name forKey:@"cm:title"];
if (description)
{
[properties setValue:description forKey:@"cm:description"];
}
self.documentFolderService = [[AlfrescoDocumentFolderService alloc] initWithSession:self.session];
SkyVaultContentFile *imageFile = nil;
if ([[name lowercaseString] hasSuffix:@".jpg"])
{
imageFile = [[AlfrescoContentFile alloc]
initWithData:UIImageJPEGRepresentation(self.selectedPhoto, 1.0)
mimeType:@"image/jpeg"];
}
else if ([[name lowercaseString] hasSuffix:@".png"])
{
imageFile = [[AlfrescoContentFile alloc]
initWithData:UIImagePNGRepresentation(self.selectedPhoto)
mimeType:@"image/png"];
}
else
{
imageFile = [[AlfrescoContentFile alloc]
initWithData:UIImageJPEGRepresentation(self.selectedPhoto, 1.0)
mimeType:@"image/jpeg"];
}
__weak AddNewItemTableViewController *weakSelf = self;
[self.documentFolderService createDocumentWithName:name
inParentFolder:self.folder
contentFile:imageFile properties:properties
completionBlock:^(AlfrescoDocument *document, NSError *error){
if (nil == document)
{
weakSelf.progressView.hidden = YES;
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:localized(@"error_title")
message:[NSString stringWithFormat:@"%@, %@", localized(@"error_uploading_document"), [error localizedDescription]]
delegate:nil
cancelButtonTitle:localized(@"dialog_cancel")
otherButtonTitles: nil];
alert.alertViewStyle = UIAlertViewStyleDefault;
[alert show];
weakSelf.photoLabel.text = localized(@"add_photo_option");
}
else
{
if (tags.count > 0)
{
// convert tag objects into strings
NSMutableArray *tagStrings = [NSMutableArray arrayWithCapacity:tags.count];
for (AlfrescoTag *tag in tags)
{
[tagStrings addObject:tag.value];
}
self.taggingService = [[AlfrescoTaggingService alloc] initWithSession:weakSelf.session];
[self.taggingService addTags:tagStrings toNode:document completionBlock:^(BOOL success, NSError *error){
if (!success)
{
weakSelf.progressView.hidden = YES;
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:localized(@"error_title")
message:[NSString stringWithFormat:@"%@, %@",localized(@"error_adding_tags"), [error localizedDescription]]
delegate:nil
cancelButtonTitle:localized(@"dialog_cancel")
otherButtonTitles:nil];
alert.alertViewStyle = UIAlertViewStyleDefault;
[alert show];
}
else
{
weakSelf.progressView.progress = 1.0;
if ([weakSelf.addNewItemDelegate respondsToSelector:@selector(updateFolderContent)])
{
[weakSelf.addNewItemDelegate updateFolderContent];
}
weakSelf.progressView.hidden = YES;
[weakSelf.navigationController popViewControllerAnimated:YES];
}
}];
}
else
{
weakSelf.progressView.progress = 1.0;
if ([weakSelf.addNewItemDelegate respondsToSelector:@selector(updateFolderContent)])
{
[weakSelf.addNewItemDelegate updateFolderContent];
}
weakSelf.progressView.hidden = YES;
[weakSelf.navigationController popViewControllerAnimated:YES];
}
}
}
progressBlock:^(NSInteger bytesUploaded, NSInteger totalBytes){
weakSelf.progressView.progress = ((float)bytesUploaded/(float)totalBytes) - 0.3;
}];
}