Ich habe ein HTML-Formular, das Benutzern ermöglicht, eine Datei hochzuladen, die dann IBM Watsons Dokumentkonvertierungs-API verwendet, um den Text des Dokuments in normalisierten Text zu konvertieren, der dann in eine Datenbank eingefügt wird.IBM Watson Document Conversion reagiert mit 415 Fehler, obwohl ich ein PDF einschließe?
Beim Testen habe ich die folgende Fehlermehrfach erhalten:
{ "Code": 415, "Fehler": „. Der Medientyp [text/plain] des Eingangsdokuments wird nicht unterstützt Auto-Korrektur wurde versucht, aber der automatisch erkannte Medientyp [text/plain] wird ebenfalls nicht unterstützt. Unterstützte Medientypen sind: application/msword, application/vnd.openxmlformats-officedocument.wordprocessingml.document, application/pdf, text/html, application/xhtml + xml. " }
Hier ist meine Form (testform.html):
<form action="testform.php" method="post" enctype="multipart/formdata">
<input type="file" name="newdoc" id="newdoc"> Upload New Doc:
</input>
<button type="submit" name="submit">Submit</button>
</form>
Und hier ist mein PHP-Skript (testform.php):
<?php
$filename = $_FILES['newdoc']['name'];
$filetype = $_FILES['newdoc']['type'];
$filesize = $_FILES['newdoc']['size'];
$filetmp = $_FILES['newdoc']['tmp_name'];
// Watson Document Conversion
$dcuser = 'arbitrary_user';
$dcpass = 'arbitrary_pwd';
$userpwd = $dcuser . ":" . $dcpass;
// Initialize cURL
$documentconversion = curl_init();
// Set POST
curl_setopt($documentconversion, CURLOPT_POST, true);
// Set DC API URL
curl_setopt($documentconversion, CURLOPT_URL,
'https://gateway.watsonplatform.net/document-
conversion/api/v1/convert_document?version=2015-12-15');
// Set Username:Password
curl_setopt($documentconversion, CURLOPT_USERPWD, $userpwd);
// Set conversion units, file, and file type
curl_setopt($documentconversion, CURLOPT_POSTFIELDS, array(
'config' => "{\"conversion_target\":\"normalized_text\"}",
'file' => '@' . realpath($filetmp) . ';type=' . $filetype
));
// Set return value
curl_setopt($documentconversion, CURLOPT_RETURNTRANSFER, true);
// Execute and get response
$response = curl_exec($documentconversion);
// Close cURL
curl_close($documentconversion);
?>
die $ response Variable enthalten würde die konvertierte Normalerweise Text, aber ich habe nichts als die oben genannten 415 Fehler bekommen, obwohl ich nur PDFs hochladen.
Irgendwelche Gedanken, warum es nicht funktioniert?
Ich habe es gerade auch ausprobiert und erhalte immer noch den Fehler 415 = \ –
Können Sie es mit einem curl-Befehl versuchen: curl -X POST -u "{username}": "{password}" -F config = "{\" conversion_target \ ": \" normalized_text \ "}" -F "[email protected]; type = application/pdf" "https://gateway.watsonplatform.net/document-conversion/api/v1/convert_document? version = 2015-12-15 " –
Fehler 401 erhalten: {" code ": 401," error ":" Nicht autorisiert "," description ":" 2017-06-15T16: 17: 17-04: 00, Fehler ERCDPLTFRM-INVLDCHR trat beim Zugriff auf https://gateway.watsonplatform.net/document-conversion/api/v1/convert_document?version=2015-12-15, Tran-Id: gateway-dp02-1290491232 - "} –