@@ -4,6 +4,8 @@ import PropTypes from 'prop-types';
4
4
import classNames from 'classnames' ;
5
5
import { faUpload } from '@fortawesome/free-solid-svg-icons/faUpload' ;
6
6
import Icon from '../../react-chayns-icon/component/Icon' ;
7
+ import supportsFileInput from '../utils/supportsFileInput' ;
8
+ import fileInputCall from '../utils/fileInputCall' ;
7
9
8
10
export default class FileInput extends PureComponent {
9
11
static types = {
@@ -78,7 +80,7 @@ export default class FileInput extends PureComponent {
78
80
super ( props ) ;
79
81
this . itemRefs = [ ] ;
80
82
this . fileInputRefs = [ ] ;
81
- this . needAppCall = ( chayns . env . isApp || chayns . env . isMyChaynsApp ) && chayns . env . isAndroid && chayns . env . appVersion < 6000 ;
83
+ this . needAppCall = supportsFileInput ( ) ;
82
84
}
83
85
84
86
onDragEnter = ( event , item , index ) => {
@@ -123,15 +125,7 @@ export default class FileInput extends PureComponent {
123
125
if ( stopPropagation ) event . stopPropagation ( ) ;
124
126
if ( typeof item . onClick === 'function' ) item . onClick ( event ) ;
125
127
if ( this . needAppCall && item . onChange ) {
126
- const uploadResult = await chayns . uploadCloudImage ( ) ;
127
- const type = uploadResult . url . match ( / ( \. [ a - z ] + ) / g) [ 0 ] ;
128
- const response = await fetch ( uploadResult . url ) ;
129
- const data = await response . blob ( ) ;
130
- const metadata = {
131
- type : `image/${ type } ` ,
132
- } ;
133
- const file = new File ( [ data ] , `androidCompatibilityUpload${ type } ` , metadata ) ;
134
- const compatibilityEvent = { target : { files : [ file ] } } ;
128
+ const compatibilityEvent = await fileInputCall ( ) ;
135
129
this . onChange ( compatibilityEvent , item , index ) ;
136
130
}
137
131
} ;
0 commit comments