Upload API via Ajax

Ritesh,
We will not be allowing FTP access to our site. We can give you limited SSH credentials.

Please look into your code to ensure that “image/” is being stripped when you parse the string.

@don-cornforthacgsystem-com,
I need access to the code that is running on your site so that I can look into the issue and can debug it as it is work perfectly fine on our demo site.

Hey Ritesh,
We just sent you those credentials.

Justyn

Hi Justyn,

As per our conversation over mail, this issue has been solved.

Hello,

Guys, Can you please share the code, How you have been fixed this ? I am also getting the upload status ‘media updated’ and it’s add the record in the db successfully but not able to uplaod the image. It shows me blank image in the profile media tab.

Please help me to solve out this.

Here is my code :

    $img = $plugin_path.'/includes/'.$m_id.'.jpg';

    $base64img = 'data:'.mime_content_type($img).';base64,'.base64_encode(file_get_contents($img));

   $url = $base_url.'/wp-admin/admin-ajax.php';

   $(document).ready(function(){
    var form_data = {};

    form_data['action'] = 'rtmedia_api';
    form_data['method'] = 'rtmedia_upload_media';
    form_data['token'] = '2704b21c7c7fd826c4f175c530b0d5db6630e3a4';
    form_data['rtmedia_file'] = '<?php echo $base64img; ?>';
    form_data['title'] = 'test image';
    form_data['context'] = 'profile';
    form_data['image_type'] = 'image/jpeg';
    
    $.ajax({
        url:'<?php echo $url; ?>',
        type:'Post',
        data:form_data,    
        success:function(response){
            alert(response);
            return false;
        }
    });    
})

Thanks !

Hi @kuldeep_kbs,

Please make sure you have encoded correct file, check with some other file to make sure whether the file is correct or not. If record in database added successfully than it mush show the image.

Check this pastebin link for sample base64 encoded image: http://pastebin.com/RtqTL2A3

Required parameters to upload media are as following:

action: "rtmedia_api"
method: "rtmedia_upload_media"
token: "access-token-here"
context: "profile"
image_type: "jpeg"
title: "test api upload"
rtmedia_file: "base64 encoded file here"

Hi @riteshpatel , I am trying to upload a image into specific album, but it is uploading to the user profile only, Please check the below code and correct me that what parameter API will accept to upload the media to user’s album, group album.

form_data['action'] = 'rtmedia_api'; form_data['method'] = 'rtmedia_upload_media'; form_data['token'] = 'token';         form_data['title'] = 'title';        form_data['context'] = 'profile';   or group in case if it's a group album           form_data['context_id'] = 'user_id';  or group_id right ?                          form_data['album_id'] = 'ablbum_id';   form_data['image_type'] = 'jpeg';    form_data['rtmedia_file'] = 'base_64_string'; 

Thanks!

Hi @kuldeep_kbs,

It was a minor issue in JSON API which we have just fixed. You can check it here: https://github.com/rtCamp/rtMedia/commit/da951e7

If you are developer, and are familiar with coding, you can make changes in plugin file for time being and make it work, it will be officially fixed in next update of rtMedia.

Hi @riteshpatel, Thanks for you update. Can we use this API through curl ?

Hi @kuldeep_kbs As we can make a post request with CURL, so I guess you can use API through CURL but I am not sure, I haven’t checked that.

Hi @riteshpatel,

Do you have any example to convert jQuery style parameters to AngularJS?

Thanks