There is any way to upload channel avatar by file url?

HI, we are using PHP curl request to creating channel and we did not found any way to upload channel avatar by a url, we have all images on cloud amazon s3,
is it possible to create channel avatar using image url?

@vibhorMaheshwari We recommend using Channel metadata to upload a channel avatar by file URL. For additional information, please visit the following link: https://docs.amity.co/technical-faq#what-is-metadata-and-its-intended-use.

so if we add file url to meta data then its will display avatar automatically in IOS uikit?

Yes, except if you use avatarCustomUrl , you will need to modify the code on your end to facilitate this.

@SocialPlus_Support
also im trying files upload api, it should be return a fileID but its giving me uploaded image below is my code:

function uploadFile($params = array())
  {
    $url = $this->api_url.'/api/v3/files';

    $headers = array(
      'Accept: application/json',
      'Authorization: Bearer '.$this->admin_token,
      'cache-control: no-cache',
      'content-type: multipart/form-data'
    );


    $fields = array();
    $fields['file']      = file_get_contents($params['file_url']);
    $fields['fullImage'] = true;
    
    // Open connection
    $ch = curl_init();

    // Set the url, number of POST vars, POST data
    curl_setopt($ch, CURLOPT_URL, $url);

    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch,CURLOPT_POSTFIELDS, $fields);

    // Execute post
    $response   = curl_exec($ch);
    $info       = curl_getinfo($ch);
    $error      = curl_error($ch);

    // Close connection
    curl_close($ch);

    $resp_array = json_decode($response, true);

    if($info['http_code'] == 200)
    { 
      $return = array('success' => true, 'response' => $resp_array);
    }
    else
    {
      $return = array('success' => false, 'error_message' => $resp_array['message'], 'response' => $resp_array);        
    }

    return $return;
  }

public function upload_file()
	{		
		$this->load->library('amity_api');
		$params = array();
		$params['file_url'] = 'https://crustpizza-media-bucket.s3.amazonaws.com/store/7fee6bcccbbee7485633f652df3162c7.jpg';
		$amity_respon = $this->amity_api->uploadFile($params);
		print_r($amity_respon);
	}

@vibhorMaheshwari I will consult with my team regarding this matter and revert to you with an update.

@vibhorMaheshwari Upon consulting with our team, we kindly suggest that you export the log response and take another look. You should be receiving a File ID as part of the response. We’re here to assist further if you need any help with this process.

@SocialPlus_Support
you can check below screen shot that i am getting http code 200 , but in response there is only image data nothing else.

Hello, could you please try this endpoint instead:

curl --location ‘https://api.amity.co/api/v4/images
–header ‘accept: application/json’
–header ‘Content-Type: application/json’
–header ‘Authorization: Bearer cxxx’
–form ‘files=@“/path/to/file”’

@SocialPlus_Support
tired this given code, but not succeed, now i am receiving a new error:

{ “status”: “error”, “message”: “Access token is invalid.”, “code”: 400100, “data”: { “detail”: { “appErrorCode”: 400100 } } }

but when i use my previous endpoint (https://apix.us.amity.co/api/v4/files) then it success but not getting fileID.

May I ask where did you get the Access token from? And did you pass the Access token when you call https://apix.us.amity.co/api/v4/files endpoint?

@SocialPlus_Support
same token passed on both api endpoints.
we have get this token from here:


e

Pls try this https://apix.us.amity.co/api/v4/images

@SocialPlus_Support
tried this endpoint (https://apix.us.amity.co/api/v4/images) and getting same response,

@SocialPlus_Support
can you please tell me what i need to do?
we are stuck on this.

Hello, could you please help test this using postman? and see if it returns correctly?

@SocialPlus_Support
yes its wokring on postman, thanks for support, now i will figure out what the issue with PHP curl request.

1 Like