Permalink
Browse files

Step 13.15: Implement upload method

  • Loading branch information...
dotansimha authored and darkbasic committed Jan 24, 2017
1 parent 38b6817 commit 02b582a2e3658f394dcd2e2d8588ca5e69d95d20
Showing with 20 additions and 1 deletion.
  1. +20 −1 src/services/picture.ts
View
@@ -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 { _ } from 'meteor/underscore';
import { DEFAULT_PICTURE_URL } from 'api/models';
@Injectable()
export class PictureService {
@@ -29,7 +32,23 @@ export class PictureService {
}
upload(blob: File): Promise<any> {
return Promise.resolve();
return new Promise((resolve, reject) => {
const metadata = _.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> {

0 comments on commit 02b582a

Please sign in to comment.