私はユーザーがIBM Watsonの文書変換APIを使用して文書のテキストを正規化されたテキストに変換し、それをデータベースに挿入するファイルをアップロードできるHTML形式を持っています。IBM Watson Document ConversionはPDFを取り込みましたが、415エラーで応答しますか?
{「コード」:415、「エラー」:
は、テスト時に、私は次のエラーを複数回受けた。「メディアタイプ[text/plainの]入力文書のサポートされていないが自動補正サポートされているメディアタイプは、application/msword、application/vnd.openxmlformats-officedocument.wordprocessingml.document、application/pdf、text/html、application/xhtml + xml "ここ}
は私のフォーム(testform.html)です:
<?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);
?>
通常$応答変数は、変換が含まれます:
<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>
そして、ここでは私のPHPスクリプト(testform.php)であります私はPDFだけをアップロードしていますが、上記の415のエラーは何も得ていません。
なぜ機能していないのでしょうか?
私はちょうどそれも試みましたが、私はまだ415エラーを取得しています。\ –
curlコマンドで試してみてください: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 " –
401エラーの取得:{" code ":401、" error ":" Not Authorized "、" description ":" 2017-06-15T16:17:17-04: 00、エラーERCDPLTFRM-INVLDCHRが発生しました。https://gateway.watsonplatform.net/document-conversion/api/v1/convert_document?version=2015-12-15、Tran-Id:gateway-dp02-1290491232 - "} –