Hey guys,
I’m still trying to build a form on an external website that makes entries in our Omeka S via the API. So far this also works wonderfully. But since I changed from application/json to multipart/form-data I don’t understand it anymore. Unfortunately I have never done that before.
I have found many tutorials that work with cURL on the CLI with Omeka. I could not transform this myself. PHP tutorials with cURL are mostly limited to file upload. We have both here, data and files.
Here is my code, I first tried to choose a static path. The upload function of the form and the saving on the server I have already completed separately. I now wanted to try to upload any image via the api.
$api_url = “XXX/api/items?key_identity=XXX&key_credential=XXX”;
$headers = array( 'Content-Type: multipart/form-data' ); $title = $_POST["title"]; $file_url = "@localhost/upload/image.jpg"; $filename = "image.jpg"; $filesize = 531949; $postfields = 'file[0]="' . $file_url . '", data={ "o:is_public": false, "o:media":[ { "o:ingester":"upload", "file_index":"0", "o:item":{ }, "dcterms:title":[ { "property_id":1, "property_label":"Title", "@value":"My media upload title", "type":"literal" } ] } ], "dcterms:title": [ { "type": "literal", "property_id": 1, "property_label": "Title", "is_public": true, "@value": "' . $title . '" } ], "o-module-mapping:marker": [ { "o-module-mapping:lat": ' . $_POST["latitute"] . ', "o-module-mapping:lng": ' . $_POST["langitute"] . ', "o-module-mapping:label": "' . $title . '" } ] }'; $curl = curl_init(); curl_setopt_array($curl, array( CURLOPT_URL => $api_url, CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => '', CURLOPT_CUSTOMREQUEST => 'POST', CURLOPT_INFILESIZE => $filesize, CURLOPT_POSTFIELDS => $postfields, CURLOPT_HTTPHEADER => $headers )); $response = curl_exec($curl); curl_close($curl); echo $response;
I think I don’t really know how to handle the $postfields.
I hope someone can help me.
Thank you so much <3
deniz