src/modules/qbContent.js
function(params, callback) {
        /**
         * Callback for QB.content.createAndUpload(params, callback).
         * @callback createAndUploadFileCallback
         * @param {object} error - The error object
         * @param {object} response - The file object (blob-object-access)
         */
        var _this = this,
            createParams= {},
            file,
            name,
            type,
            size,
            fileId;

        var clonedParams = JSON.parse(JSON.stringify(params));

        clonedParams.file.data = "...";

        file = params.file;
        name = params.name || file.name;
        type = params.type || file.type;
        size = params.size || file.size;

        createParams.name = name;
        createParams.content_type = type;

        if (params.public) {
            createParams.public = params.public;
        }

        if (params.tag_list) {
            createParams.tag_list = params.tag_list;
        }

        // Create a file object
        this.create(createParams, function(err, createResult){
            if (err) {
                callback(err, null);
            } else {
                var uri = parseUri(createResult.blob_object_access.params),
                    uploadUrl = uri.protocol + "://" + uri.authority + uri.path,
                    uploadParams = {url: uploadUrl},
                    data = {};

                fileId = createResult.id;
                createResult.size = size;

                Object.keys(uri.queryKey).forEach(function(val) {
                    data[val] = decodeURIComponent(uri.queryKey[val]);
                });

                data.file = file;
                uploadParams.data = data;

                // Upload the file to Amazon S3
                _this.upload(uploadParams, function(err, result) {
                    if (err) {
                        callback(err, null);
                    } else {
                        // Mark file as uploaded
                        _this.markUploaded({
                            id: fileId,
                            size: size
                        }, function(err, result){
                            if (err) {
                                callback(err, null);
                            } else {
                                callback(null, createResult);
                            }
                        });
                    }
                });
            }
        });
    }
function(params, callback) {
        /**
         * Callback for QB.content.createAndUpload(params, callback).
         * @callback createAndUploadFileCallback
         * @param {object} error - The error object
         * @param {object} response - The file object (blob-object-access)
         */
        var _this = this,
            createParams= {},
            file,
            name,
            type,
            size,
            fileId;

        var clonedParams = JSON.parse(JSON.stringify(params));

        clonedParams.file.data = "...";

        file = params.file;
        name = params.name || file.name;
        type = params.type || file.type;
        size = params.size || file.size;

        createParams.name = name;
        createParams.content_type = type;

        if (params.public) {
            createParams.public = params.public;
        }

        if (params.tag_list) {
            createParams.tag_list = params.tag_list;
        }

        // Create a file object
        this.create(createParams, function(err, createResult){
            if (err) {
                callback(err, null);
            } else {
                var uri = parseUri(createResult.blob_object_access.params),
                    uploadUrl = uri.protocol + "://" + uri.authority + uri.path,
                    uploadParams = {url: uploadUrl},
                    data = {};

                fileId = createResult.id;
                createResult.size = size;

                Object.keys(uri.queryKey).forEach(function(val) {
                    data[val] = decodeURIComponent(uri.queryKey[val]);
                });

                data.file = file;
                uploadParams.data = data;

                // Upload the file to Amazon S3
                _this.upload(uploadParams, function(err, result) {
                    if (err) {
                        callback(err, null);
                    } else {
                        // Mark file as uploaded
                        _this.markUploaded({
                            id: fileId,
                            size: size
                        }, function(err, result){
                            if (err) {
                                callback(err, null);
                            } else {
                                callback(null, createResult);
                            }
                        });
                    }
                });
            }
        });
    }
function ( params , callback ) { /**
         * Callback for QB.content.createAndUpload(params, callback).
         * @callback createAndUploadFileCallback
         * @param {object} error - The error object
         * @param {object} response - The file object (blob-object-access)
         */ var _this = this , createParams = { } , file , name , type , size , fileId ; var clonedParams = JSON . parse ( JSON . stringify ( params ) ) ; clonedParams . file . data = "..." ; file = params . file ; name = params . name || file . name ; type = params . type || file . type ; size = params . size || file . size ; createParams . name = name ; createParams . content_type = type ; if ( params . public ) { createParams . public = params . public ; } if ( params . tag_list ) { createParams . tag_list = params . tag_list ; } // Create a file object this . create ( createParams , function ( err , createResult ) { if ( err ) { callback ( err , null ) ; } else { var uri = parseUri ( createResult . blob_object_access . params ) , uploadUrl = uri . protocol + "://" + uri . authority + uri . path , uploadParams = { url : uploadUrl } , data = { } ; fileId = createResult . id ; createResult . size = size ; Object . keys ( uri . queryKey ) . forEach ( function ( val ) { data [ val ] = decodeURIComponent ( uri . queryKey [ val ] ) ; } ) ; data . file = file ; uploadParams . data = data ; // Upload the file to Amazon S3 _this . upload ( uploadParams , function ( err , result ) { if ( err ) { callback ( err , null ) ; } else { // Mark file as uploaded _this . markUploaded ( { id : fileId , size : size } , function ( err , result ) { if ( err ) { callback ( err , null ) ; } else { callback ( null , createResult ) ; } } ) ; } } ) ; } } ) ; }
Create file > upload file > mark file as uploaded > return result.
@memberof QB.content
@param {object} params - Object of parameters
@param {object} params.file - File object
@param {string} params.name - The file's name
@param {string} params.type - The file's mime ({@link https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Complete_list_of_MIME_types content type})
@param {number} params.size - Size of file, in bytes
@param {boolean} [params.public=false] - The file's visibility. public means it will be possible to access this file without QuickBlox session token provided. Default is 'false'
@param {createAndUploadFileCallback} callback - The createAndUploadFileCallback function
Create file > upload file > mark file as uploaded > return result .