Merge pull request #8331 from RocketChat/mobile-file-upload

[FIX-RC] Mobile file upload not working
pull/8461/head
Rodrigo Nascimento 8 years ago
parent 16ecc69f22
commit 7827574549
No known key found for this signature in database
GPG Key ID: CFCE33B7B01AC335
  1. 47
      packages/rocketchat-ui-message/startup/messageBoxActions.js

@ -1,4 +1,4 @@
/* globals fileUpload popover chatMessages AudioRecorder */
/* globals fileUpload chatMessages AudioRecorder device */
import mime from 'mime-type/with-db';
import {VRecDialog} from 'meteor/rocketchat:ui-vrecord';
@ -46,32 +46,35 @@ RocketChat.messageBox.actions.add('Add_files_from', 'Computer', {
id: 'file-upload',
icon: 'computer',
condition: () => RocketChat.settings.get('FileUpload_Enabled'),
action() {
setTimeout(() => {
popover.close();
const input = document.createElement('input');
input.style.display = 'none';
input.type = 'file';
input.setAttribute('multiple', 'multiple');
document.body.appendChild(input);
action({event}) {
event.preventDefault();
const input = document.createElement('input');
input.style.display = 'none';
input.type = 'file';
input.setAttribute('multiple', 'multiple');
document.body.appendChild(input);
input.click();
// Simple hack for cordova aka codegueira
if (typeof device !== 'undefined' && device.platform && device.platform.toLocaleLowerCase() === 'ios') {
input.click();
}
input.addEventListener('change', function(e) {
const filesToUpload = [...e.target.files].map(file => {
Object.defineProperty(file, 'type', {
value: mime.lookup(file.name)
});
return {
file,
name: file.name
};
input.addEventListener('change', function(e) {
const filesToUpload = [...e.target.files].map(file => {
Object.defineProperty(file, 'type', {
value: mime.lookup(file.name)
});
return fileUpload(filesToUpload);
}, {once: true});
return {
file,
name: file.name
};
});
return fileUpload(filesToUpload);
}, {once: true});
input.remove();
}, 100);
input.remove();
}
});

Loading…
Cancel
Save