rtMedia upload API is not working

I want to use the rtMedia upload API, I am following this doc “http://docs.rtcamp.com/rtmedia/developer/api/rtmedia-api/endpoints/upload-endpoint/”. I am trying to post the media data programmatically as on defined endpont ‘http://yousite.com/members/username/upload/ (a BuddyPress profile)’. But I am getting a blank response from my ajax request. If I encoded the data into JSON then it will return me the html of the endpont url as in ajax response.

Please check the code below and please let me know at which manners
it will work.



$(document).ready(function(){

        var form_data = {};

        var files = {};

        

        files['name'] = 'abc.jpg';

        files['type'] = 'image/jpeg';

        files['tmp_name'] = '<?php echo $img; ?>';   // $img =
files already on the server 
/server_path/includes/946968884626505178_1755025174.jpg

        files['error'] = 'UPLOAD_ERR_OK';

        files['size'] = '';



        form_data['mode'] = 'file_upload';

        form_data['title'] = 'abc';

        form_data['context'] = 'profile';

        form_data['context_id'] = '4';

        form_data['album_id'] = '1';

        form_data['files'] = files;

        

        var fdata;

        fdata = JSON.stringify(form_data);

        

        $.ajax({

            url:'<?php echo $url; ?>',   // $url =
http://sever_url/wpinstagram/members/anku/upload/

            type:'Post',

            data:form_data,    

            success:function(response){

                alert(response);

                return false;

            }

        });    

    })

Hi @kuldeep_kbs,

You were missing nonce field to upload media. Also, there was some error in your code. Please check below updated code.

//php code to generate nonce
$nonce = RTMediaUploadView::upload_nonce_generator ( false );
localise nonce so that you can use it in js

// js code to use upload endpoint
var form_data = {};

var files = {};

files['name'] = 'abc.jpg';
files['type'] = 'image/jpeg';
files['tmp_name'] = 'file on the server'
files['error'] = '0';
files['size'] = '';

form_data['mode'] = 'file_upload';
form_data['title'] = 'abc';
form_data['context'] = 'profile';
form_data['context_id'] = '1';
form_data['album_id'] = '1';
form_data['files'] = files;
form_data['rtmedia_upload_nonce'] = 'nonce value here';
form_data['action'] = 'wp_handle_upload';

jQuery.ajax({
    url:'your ajax url',
    type:'post',
    data:form_data,    
    success:function(response){
        console.log(response);
    }
});

@riteshpatel Can you please respond me here Upload API via Ajax, I am getting the same problem as discussed here so I am following this thread now. I think nonce field not defined for the JSON API

Thanks !