1+
2+
3+ export const upload = async ( file , { cloud, options } ) => {
4+ if ( ! file ) {
5+ throw new Error ( 'file is required!' )
6+ }
7+
8+ if ( ! cloud || ! cloud . cloudName ) {
9+ throw new Error ( 'cloud.cloudName is required!' )
10+ }
11+
12+ const resourceType = options . resourceType || 'image'
13+
14+ const path = `${ UPLOAD_PREFIX } /v1_1/${ cloud . cloudName } /${ resourceType } /upload`
15+
16+
17+ }
18+
19+ function random_public_id ( ) {
20+ return crypto . randomBytes ( 12 ) . toString ( 'base64' ) . replace ( / [ ^ a - z 0 - 9 ] / g, "" ) ;
21+ }
22+
23+ exports . upload = function upload ( file , callback , options = { } ) {
24+ return call_api ( "upload" , callback , options , function ( ) {
25+ let params = build_upload_params ( options ) ;
26+ return isRemoteUrl ( file ) ? [ params , { file : file } ] : [ params , { } , file ] ;
27+ } ) ;
28+ } ;
29+
30+ exports . unsigned_upload = function unsigned_upload ( file , upload_preset , callback , options = { } ) {
31+ return exports . upload ( file , callback , merge ( options , {
32+ unsigned : true ,
33+ upload_preset : upload_preset
34+ } ) ) ;
35+ } ;
36+
37+ exports . upload_large = function upload_large ( path , callback , options = { } ) {
38+ if ( ( path != null ) && isRemoteUrl ( path ) ) {
39+ // upload a remote file
40+ return exports . upload ( path , callback , options ) ;
41+ }
42+ if ( path != null && ! options . filename ) {
43+ options . filename = path . split ( / ( \\ | \/ ) / g) . pop ( ) . replace ( / \. [ ^ / . ] + $ / , "" ) ;
44+ }
45+ return exports . upload_chunked ( path , callback , extend ( {
46+ resource_type : 'raw'
47+ } , options ) ) ;
48+ } ;
49+
50+ exports . explicit = function explicit ( public_id , callback , options = { } ) {
51+ return call_api ( "explicit" , callback , options , function ( ) {
52+ return utils . build_explicit_api_params ( public_id , options ) ;
53+ } ) ;
54+ } ;
0 commit comments