Browse Source

Fix file uploads (for avatar)

master
morethanwords 4 years ago
parent
commit
af9fc5479e
  1. 22
      src/lib/appManagers/appDownloadManager.ts

22
src/lib/appManagers/appDownloadManager.ts

@ -80,8 +80,26 @@ export class AppDownloadManager {
return deferred; return deferred;
} }
public upload(file: File | Blob) { public upload(file: File | Blob, fileName?: string) {
const fileName = /* (file as File).name || */'upload-' + this.uploadID++; if(!fileName) {
const mimeType = file?.type;
if(mimeType) { // the same like apiFileName in appMessagesManager for upload!
const ext = this.uploadID++ + '.' + mimeType.split('/')[1];
if(['image/jpeg', 'image/png', 'image/bmp'].indexOf(mimeType) >= 0) {
fileName = 'photo' + ext;
} else if(mimeType.indexOf('audio/') === 0 || ['video/ogg'].indexOf(mimeType) >= 0) {
fileName = 'audio' + ext;
} else if(mimeType.indexOf('video/') === 0) {
fileName = 'video' + ext;
} else {
fileName = 'document' + ext;
}
} else {
fileName = 'upload-' + this.uploadID++;
}
}
const deferred = this.getNewDeferred(fileName); const deferred = this.getNewDeferred(fileName);
apiManager.uploadFile({file, fileName}).then(deferred.resolve, deferred.reject); apiManager.uploadFile({file, fileName}).then(deferred.resolve, deferred.reject);

Loading…
Cancel
Save