@@ -17,14 +17,18 @@ const sampleApp = async () => {
1717 // Uploading images through binary
1818 let i = 0 ;
1919 while ( i < 8 ) {
20- const response = await uploadFileBin ( imagekit , FILE_PATH , `${ FILE_NAME } _bin_${ i + 1 } ` ) ;
20+ const response = await uploadLocalFile ( imagekit , FILE_PATH , `${ FILE_NAME } _bin_${ i + 1 } ` ) ;
2121 console . log ( `Binary upload response # ${ i + 1 } :` , JSON . stringify ( response , undefined , 2 ) , "\n" ) ;
2222 i ++ ;
2323 }
2424
2525 // Uploading images with base64
2626 const uploadResponse_base64 = await uploadFileBase64 ( imagekit , FILE_PATH , `${ FILE_NAME } _base64` ) ;
2727 console . log ( `Base64 upload response:` , JSON . stringify ( uploadResponse_base64 , undefined , 2 ) , "\n" ) ;
28+
29+ // Uploading images with buffer
30+ const uploadResponse_buffer = await uploadFileBuffer ( imagekit , FILE_PATH , `${ FILE_NAME } _buffer` ) ;
31+ console . log ( `Buffer upload response:` , JSON . stringify ( uploadResponse_buffer , undefined , 2 ) , "\n" ) ;
2832
2933 // Uploading images with URL
3034 const uploadResponse_url = await uploadFileURL ( imagekit , IMG_URL , `${ FILE_NAME } _url` ) ;
@@ -102,12 +106,18 @@ const sampleApp = async () => {
102106
103107}
104108
105- const uploadFileBin = async ( imagekitInstance , filePath , fileName ) => {
109+ const uploadLocalFile = async ( imagekitInstance , filePath , fileName ) => {
106110 const file = fs . createReadStream ( filePath ) ;
107111 const response = await imagekitInstance . upload ( { file, fileName} ) ;
108112 return response ;
109113}
110114
115+ const uploadFileBuffer = async ( imagekitInstance , filePath , fileName ) => {
116+ const buffer = fs . readFileSync ( filePath ) ;
117+ const response = await imagekitInstance . upload ( { file : buffer , fileName} ) ;
118+ return response ;
119+ }
120+
111121const uploadFileBase64 = async ( imagekitInstance , filePath , fileName ) => {
112122 const file_base64 = fs . readFileSync ( filePath , 'base64' ) ;
113123 const response = await imagekitInstance . upload ( { file : file_base64 , fileName} ) ;
0 commit comments