add progress bar for file uploads resolves #53

This commit is contained in:
Morgan McMillian 2018-02-24 07:22:13 -08:00
parent 305b570cfa
commit e5cdc80b64

View file

@ -361,6 +361,7 @@ export class StreamPage {
</button>
</ion-col>
</ion-row>
<progress id='p' *ngIf="showProgress"></progress>
<ion-list>
<ion-item *ngFor="let f of files">
<ion-thumbnail item-start>
@ -380,6 +381,7 @@ export class NewPostModal {
title: string;
replyid: string;
ptext: string = "";
showProgress: boolean = false;
files: Array<Object> = [];
fname: string = "";
fpath: string = "";
@ -491,7 +493,7 @@ export class NewPostModal {
}
attachImage() {
console.log('file chooser');
// console.log('file chooser');
const fileTransfer: FileTransferObject = this.transfer.create();
this.fileChooser.open().then(uri => {
@ -499,9 +501,6 @@ export class NewPostModal {
this.filePath.resolveNativePath(uri).then(filePath => {
this.fpath = filePath;
this.fname = filePath.split('/').pop();
console.log('-filepath-');
console.log(this.fpath);
console.log(this.fname);
let options: FileUploadOptions = {
fileKey: 'content',
@ -514,10 +513,9 @@ export class NewPostModal {
headers: {'Authorization': 'Bearer ' + this.authToken}
}
this.showProgress = true;
fileTransfer.upload(this.fpath, 'https://api.pnut.io/v0/files', options).then((response) => {
console.log('-file created-');
console.log(response.response);
console.log('-file created-');
let rdata = JSON.parse(response.response);
let oembed = {
'+io.pnut.core.file': {
@ -526,7 +524,7 @@ export class NewPostModal {
format: 'oembed'
}
}
console.log(JSON.stringify(oembed));
// console.log(JSON.stringify(oembed));
this.raw.push({
type: "io.pnut.core.oembed",
value: oembed
@ -536,10 +534,10 @@ export class NewPostModal {
link: rdata.data.link,
id: this.raw.length - 1
});
this.showProgress = false;
}).catch((err) => {
console.log('-create file error-');
console.log(JSON.stringify(err));
console.log('-create file error-');
this.showProgress = false;
let edata = JSON.parse(err.body);
this.presentToast(edata.meta.error_message);
});