CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using Core CiviCRM Functions (Moderator: Yashodha Chaku) »
  • Using API to upload files to contact
Pages: [1]

Author Topic: Using API to upload files to contact  (Read 920 times)

jeffmikels

  • I’m new here
  • *
  • Posts: 26
  • Karma: 0
Using API to upload files to contact
December 11, 2012, 01:01:42 pm
I'm using a Custom File Field so that each contact can have an image associated with their contact. However, I've made extensive use of the api to create a custom edit page that exposes only the most relevant information to my data entry team.

What I want to know is if there is a way to use the API to allow my data entry team to upload photos through my custom edit page.

Can anyone point me in the right direction? I have scanned the forums and the documentation and can find no documentation about using the API to upload a file and attach it to a Custom File Field. Do I need to write my own?

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: Using API to upload files to contact
December 11, 2012, 02:15:00 pm

yeah, i suspect u will need to write your own. I did a quick search in the api/v3 directory and could not find too much code related to this.

There is: api/v3/File.php but i'm not sure what/where it can be used

The code here:

http://svn.civicrm.org/sfschool/trunk/org.civicrm.school/bin/addReportCards.php

show how i added a bunch of reportCards in batch to a multi-record custom contact field. That should give u a decent idea on the schema

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

jeffmikels

  • I’m new here
  • *
  • Posts: 26
  • Karma: 0
Re: Using API to upload files to contact
December 11, 2012, 02:40:36 pm
Thanks for the input. If I write my own, I'm gathering I need to do these steps on the server:

  • receive the file
  • move the file to the proper civicrm assets directory
  • use the api to create the custom field data

I know where civicrm puts all uploaded files on my server, so I can hardcode that path, but I'd prefer to grab that setting from civicrm using the api if possible. Can that path data be retrieved somehow using the api?

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: Using API to upload files to contact
December 11, 2012, 04:05:14 pm

the path where the custom files are stored is in the config object, u can get it from:

$config = CRM_Core_Config::singleton();
$config->customFileUploadDir

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: Using API to upload files to contact
December 11, 2012, 04:56:55 pm
Eileen is introducing on 4.3 a new setting api that is going to expose these configuration values. In the meantime, using the core config object is your best option and that's the way it's done in civicrm core.

As for the file api, are you going to use ajax or rest interface to upload or only php?

X+
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

jeffmikels

  • I’m new here
  • *
  • Posts: 26
  • Karma: 0
Re: Using API to upload files to contact
December 14, 2012, 03:13:38 pm
I've been calling the api with php directly. Will the CRM_Core_Config exist if I only load the civicrm_api php file?

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: Using API to upload files to contact
December 18, 2012, 02:47:51 pm
As long as you start your script with

civicrm_initialize();

Then the config object will exist (& you won't need to require_once api.php)
Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using Core CiviCRM Functions (Moderator: Yashodha Chaku) »
  • Using API to upload files to contact

This forum was archived on 2017-11-26.