Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Step 13.16: Implement upload method
  • Loading branch information
dotansimha authored and darkbasic committed Oct 16, 2017
1 parent 70e2019 commit decc114
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion src/services/picture.ts
Expand Up @@ -2,6 +2,9 @@ import { Injectable } from '@angular/core';
import { Platform } from 'ionic-angular';
import { ImagePicker } from '@ionic-native/image-picker';
import { UploadFS } from 'meteor/jalik:ufs';
import { PicturesStore } from 'api/collections';
import * as _ from 'lodash';
import { DEFAULT_PICTURE_URL } from 'api/models';

@Injectable()
export class PictureService {
Expand Down Expand Up @@ -29,7 +32,23 @@ export class PictureService {
}

upload(blob: File): Promise<any> {
return Promise.resolve();
return new Promise((resolve, reject) => {
const metadata: any = _.pick(blob, 'name', 'type', 'size');

if (!metadata.name) {
metadata.name = DEFAULT_PICTURE_URL;
}

const upload = new UploadFS.Uploader({
data: blob,
file: metadata,
store: PicturesStore,
onComplete: resolve,
onError: reject
});

upload.start();
});
}

convertURLtoBlob(url: string, options = {}): Promise<File> {
Expand Down

0 comments on commit decc114

Please sign in to comment.