Skip to content

Commit

Permalink
Merge pull request #8331 from RocketChat/mobile-file-upload
Browse files Browse the repository at this point in the history
[FIX-RC] Mobile file upload not working
  • Loading branch information
rodrigok committed Sep 29, 2017
1 parent 16ecc69 commit 7827574
Showing 1 changed file with 25 additions and 22 deletions.
47 changes: 25 additions & 22 deletions packages/rocketchat-ui-message/startup/messageBoxActions.js
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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();
}
});

Expand Down

0 comments on commit 7827574

Please sign in to comment.