mirror of
https://github.com/ascribe/onion.git
synced 2024-12-22 17:33:14 +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:
parent
b9e41d5cba
commit
d5823f10ec
@ -1,5 +1,7 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
import MimeTypes from '../../constants/mime_types';
|
||||||
|
|
||||||
export const formSubmissionValidation = {
|
export const formSubmissionValidation = {
|
||||||
/**
|
/**
|
||||||
* Returns a boolean if there has been at least one file uploaded
|
* Returns a boolean if there has been at least one file uploaded
|
||||||
@ -69,12 +71,14 @@ export function displayValidProgressFilesFilter(file) {
|
|||||||
*
|
*
|
||||||
* Takes an array of file extensions (['pdf', 'png', ...]) and transforms them into a string
|
* Takes an array of file extensions (['pdf', 'png', ...]) and transforms them into a string
|
||||||
* that can be passed into an html5 input via its 'accept' prop.
|
* that can be passed into an html5 input via its 'accept' prop.
|
||||||
* @param {array} allowedExtensions Array of strings without a dot prefixed
|
* @param {array} allowedExtensions Array of strings without a dot prefixed
|
||||||
* @return {string} Joined string (comma-separated) of the passed-in array
|
* @return {string} Joined string (comma-separated) of the passed-in array
|
||||||
*/
|
*/
|
||||||
export function transformAllowedExtensionsToInputAcceptProp(allowedExtensions) {
|
export function transformAllowedExtensionsToInputAcceptProp(allowedExtensions) {
|
||||||
// add a dot in front of the extension
|
// 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) => '.' + ext);
|
let prefixedAllowedExtensions = allowedExtensions.map((ext) => {
|
||||||
|
return MimeTypes[ext] || ('.' + ext);
|
||||||
|
});
|
||||||
|
|
||||||
// generate a comma separated list to add them to the DOM element
|
// 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
|
// See: http://stackoverflow.com/questions/4328947/limit-file-format-when-using-input-type-file
|
||||||
|
11
js/constants/mime_types.js
Normal file
11
js/constants/mime_types.js
Normal 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;
|
Loading…
Reference in New Issue
Block a user