Unable to upload a pdf document using dr chrono api via php cURL

血红的双手。 提交于 2021-02-08 08:16:18

问题


I am using php curl to upload pdf document using in dr chrono using api/documents. Actually I am not clear on how to pass my pdf file so that it gets uploaded.

Here is my params array

$handle = fopen('pdfsPatientInformation_1446467593.pdf', 'r');
$myfile = fgets($handle);

$docParams = array('doctor' => 7891,'patient' => 58001561,'description' =>'Patient Medical History Form','date' => '2015-02-11','document' => $myfile);

I am getting error

{"document":["The submitted data was not a file. Check the encoding type on the form."]}

Please can you help me with an answer.


回答1:


Make sure you're POSTing with the encoding "multipart/form-data"

With PHP CURL:

<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL, $THE_REMOTE_URL_YOU_ARE_POSTING_TO);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, array(
    'document' => "@/Users/username/Desktop/test.pdf",
    'doctor' => "7891",
    'patient' => "58001561",
    'date' => "2015-11-02",
    'description' => "Patient Medical History Form"
  )); 
$response = curl_exec($ch);
?>

With HTML:

<form method="post" enctype="multipart/form-data">
    <input type="text" name="doctor" value="7891">
    <input type="text" name="patient" value="58001561">
    <input type="text" name="description" value="Patient Medical History Form">
    <input type="text" name="date" value="2015-11-02">
    <input type="file" name="document">
    <input type="submit" name="submit" value="Upload">
</form>

Or with curl:

curl -F "doctor=7891" -F "patient=58001561" -F "description=Patient Medical History" \
-F "date=2015-11-02" -F "document=@/Users/yourusername/Desktop/test.pdf" https://drchrono.com/api/endpoint/here


来源:https://stackoverflow.com/questions/33496789/unable-to-upload-a-pdf-document-using-dr-chrono-api-via-php-curl

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!