Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX-RC] Mobile file upload not working #8331

Merged
merged 2 commits into from
Sep 29, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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