This repository has been archived by the owner on Apr 17, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 59
CollectionFS
Michael Arthur edited this page Dec 29, 2014
·
1 revision
Meteor.method
Note I have a normal Panel collection and a normal Images collection, and then CollectionFS collection is called ImageFiles.
'SaveImageToPanel': function(params) {
var panel = Panels.findOne(params.panelId);
// can't do shit without the panel to attach it to
if (panel) {
var decodedBuffer = new Buffer(params.imageData, 'base64');
var newFile = new FS.File();
newFile.name('panel.jpg');
newFile.attachData(decodedBuffer, {type: 'image/jpeg'}, function (error) {
if (error) throw error;
var imageFile = ImageFiles.insert(newFile);
//create a new image object to encapsulate this
var imageUrl = newFile.url({brokenIsFine : true});
var newImageObjectId = Images.insert({"owningObjectId": params.panelId, "imageFileId": imageFile._id, "imageUrl" : imageUrl});
Panels.update({"_id": params.panelId}, {$set: {currentImage: newImageObjectId}});
});
}
}
The OS X client objective-C
This should be easy to convert to work in iOS also
- (void)saveImage:(NSImage *)image toPanel:(NSString *)panelId
{
NSBitmapImageRep *bitmap = [[NSBitmapImageRep alloc] initWithData:[image TIFFRepresentation]];
NSData *data = [bitmap representationUsingType:NSJPEGFileType properties:nil];
NSData *encodedData = [data base64EncodedDataWithOptions:NSDataBase64Encoding64CharacterLineLength];
NSString *encodedString = [NSString stringWithUTF8String:[encodedData bytes]];
NSArray *params = @[@{@"panelId": panelId, @"imageData" : encodedString}];
[_meteor callMethodName:@"SaveImageToPanel" parameters:params responseCallback:^(id response, NSError *error){
NSLog(@"%@!", error);
}];
}