Than you for your help.
Indeed, using â/mediaâ instead of â/filesâ seems to be better. However I still have an issue: the result is now only false.
My PHP file and the curl command you give return the same result false without other explanation.
I just tried to change o:id value and file_index value.
Can you explain me how to correctly set JSon properties and values, please?
I have solved my problem: the âlogâ file extension was not in âallowed file extensionâ list (in admin settings). My bad!
Thank you a lot for your help!
So, this is my well-working PHP code:
$apiUrl="http://localhost/omeka-s/api";
$apiUrl.="/media";
$apiUrl.="?key_identity=XXX&key_credential=YYY";
$data = [];
$itemId=7;
$array=[
"o:ingester"=> "upload",
"file_index"=> "0",
"o:item"=> ["o:id" => $itemId]
];
$data['data']=json_encode($array);
$data['file[0]'] = new CURLFile('test.txt','text/plain','newFileName');
// Note that the value must be a string, not an array (CURLFile objects are
//automatically parsed into String) so you must set the key as 'file[0]'
$options=[
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POSTFIELDS => $data,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_HTTPHEADER => ['Content-Type: multipart/form-data']
];
$ch = curl_init($apiUrl);
curl_setopt_array($ch, $options);
$result=curl_exec($ch);
curl_close($ch);
var_dump($result);
Yes, thereâs a problem at work here causing just the âfalseâ return. We should be returning a more understandable error in this case, and weâre looking into why thatâs not the case.
This problem (of the error not being properly reported through the API) is now fixed in the develop branch, and so will be fixed in the next beta release.
Reports nicely: {"errors":{"upload":["Error ingesting \u0022Aleo-Regular.woff\u0022. Cannot store files with the media type \u0022application\/octet-stream\u0022.","Error ingesting \u0022Aleo-Regular.woff\u0022. Cannot store files with the resolved extension \u0022woff\u0022."]}}
However, I can upload files like âmodel.wapitiâ and csv files even though they are not listed in allowed extensions?
Whatâs happening with CSV probably is that weâre detecting that itâs a plain text file and further detecting that .txt is the preferred extension for text/plain, and .txt is in the allowed list. If you look at the file we actually stored, I believe youâll see that the extension was changed to .txt when we stored it.
There may be a bug at play here as well though⌠the extension guessing system is really in place to get some extension when one isnât provided⌠it shouldnât be making these kinds of changes.