1
0
mirror of https://github.com/ascribe/onion.git synced 2024-12-22 09:23:13 +01:00

Use mime types for input's accept property as safari doesn't play nicely with just the extensions

This commit is contained in:
Brett Sun 2015-12-10 17:54:33 +01:00
parent b9e41d5cba
commit d5823f10ec
2 changed files with 19 additions and 4 deletions

View File

@ -1,5 +1,7 @@
'use strict';
import MimeTypes from '../../constants/mime_types';
export const formSubmissionValidation = {
/**
* Returns a boolean if there has been at least one file uploaded
@ -73,8 +75,10 @@ export function displayValidProgressFilesFilter(file) {
* @return {string} Joined string (comma-separated) of the passed-in array
*/
export function transformAllowedExtensionsToInputAcceptProp(allowedExtensions) {
// add a dot in front of the extension
let prefixedAllowedExtensions = allowedExtensions.map((ext) => '.' + ext);
// Get the mime type of the extension if it's defined or add a dot in front of the extension
let prefixedAllowedExtensions = allowedExtensions.map((ext) => {
return MimeTypes[ext] || ('.' + ext);
});
// generate a comma separated list to add them to the DOM element
// See: http://stackoverflow.com/questions/4328947/limit-file-format-when-using-input-type-file

View File

@ -0,0 +1,11 @@
'use strict';
const MimeTypes = {
'jpg': 'image/jpeg',
'jpeg': 'image/jpeg',
'gif': 'image/gif',
'pdf': 'application/pdf',
'png': 'image/png'
};
export default MimeTypes;