@@ -385,15 +385,14 @@ module.exports = function(AV) {
385385 data . blob . type = guessedType ;
386386 }
387387 this . _source = AV . Promise . as ( data . blob , guessedType ) ;
388- } else if ( typeof ( File ) !== "undefined" && data instanceof global . File ) {
388+ } else if ( typeof File !== "undefined" && data instanceof global . File ) {
389389 this . _source = AV . Promise . as ( data , guessedType ) ;
390- } else if ( avConfig . isNode && global . Buffer . isBuffer ( data ) ) {
390+ } else if ( typeof Buffer !== "undefined" && global . Buffer . isBuffer ( data ) ) {
391391 // use global.Buffer to prevent browserify pack Buffer module
392- this . attributes . base64 = data . toString ( 'base64' ) ;
393- this . _source = AV . Promise . as ( this . attributes . base64 , guessedType ) ;
394392 this . attributes . metaData . size = data . length ;
393+ this . _source = AV . Promise . as ( data , guessedType ) ;
395394 } else if ( _ . isString ( data ) ) {
396- throw "Creating a AV.File from a String is not yet supported." ;
395+ throw new Error ( "Creating a AV.File from a String is not yet supported." ) ;
397396 }
398397 } ;
399398
@@ -720,6 +719,9 @@ module.exports = function(AV) {
720719 if ( this . attributes . base64 ) {
721720 data . base64 = this . attributes . base64 ;
722721 return AV . _request ( 'files' , this . attributes . name , null , 'POST' , data ) ;
722+ } else if ( typeof Buffer !== "undefined" && global . Buffer . isBuffer ( file ) ) {
723+ data . base64 = file . toString ( 'base64' ) ;
724+ return AV . _request ( 'files' , this . attributes . name , null , 'POST' , data ) ;
723725 } else {
724726 return readAsync ( file ) . then ( function ( base64 ) {
725727 data . base64 = base64 ;
0 commit comments