Child pages
  • Chapitre 9 - Gestion des images
Skip to end of metadata
Go to start of metadata

Accès aux images

L'accès aux images se fait via l'entité "images"

Plusieurs types d'image existent :

  • Générale à la boutique
  • Produit
  • Catégorie
  • Fabricant
  • Fournisseur
  • Magasin

Chacun de ces types d'images est accessible via les liens suivants :

  • /api/images/general
  • /api/images/products
  • /api/images/categories
  • /api/images/manufacturers
  • /api/images/suppliers
  • /api/images/stores

Différentes tailles d'images sont disponible en fonction des types d'images.

Celles ci sont accessible via les lien ci dessus et se trouve sous forme XML englobé dans le nœud image_types.

Exemples :

L'image du produit 5 ayant comme identifiant d'image 10 s'accède de cette manière :

/api/images/products/5/10

Modification des images

Pour modifier les images il faut envoyer en POST le paramètre ayant comme nom image.

Exemple modification de l'image de la catégorie 2 :

Méthode HTTP : PUT

URL : /images/categories/2

Paramètres : images=[Contenu binaire de l'image à envoyer]

Exemple d'ajout d'une image produit au produit ayant pour identifiant 1 :

Méthode HTTP : POST

URL : /images/products/1

Paramètres : images=[Contenu binaire de l'image à envoyer]

Code HTML permettant au navigateur d'envoyer l'image associée :


<form enctype="multipart/form-data" method="POST" action="http://[email protected]/api/images/products/1">
<fieldset>
<legend>Add image for products No 1</legend>
<input type="file" name="image">
<input type="submit" value="Execute">
</fieldset>
</form>

Code en utilisant CURL :


$url = 'http://maboutique.com/api/images/products/1';
$image_path = 'C:\\mon_image.png';
$key = 'Ma clé webservice';


$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
//curl_setopt($ch, CURLOPT_PUT, true); Pour modifier une image
curl_setopt($ch, CURLOPT_USERPWD, $key.':');
curl_setopt($ch, CURLOPT_POSTFIELDS, array('image' => '@'.$image_path));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
curl_close($ch);

  • No labels