1

curl_file_create creates a CURLFile. I need to create an equivalent object in java (possibly using HttpUrlConnection).

Here is the background:

I am trying to POST to a REST service hosted by a medical record system. The MIME type expected by the service is "multipart/form." I am assuming this is a documentation typo and they mean "multipart/form-data"

The call takes a few POST params, one of which is "attachmentcontents". Basically I have to supply the contents of my file that I want to upload to this param. How would I do this?

Now, when I try the following using CURL, I do succeed in uploading the attachment:

$object = array(
                'Content-Type' => 'multipart/form',
                'documentsubclass' => 'MEDICALRECORD_GROWTHCHART',
                'departmentid' => <departmentId>,
                'appointmentid' => <appointmentId>,
                'attachmentcontents' => function_exists('curl_file_create') ? curl_file_create($file) : "@{$file}"
            );
            $result = $this->call("{practiceid}/patients/{$patientId}/documents", $object, 'XPOST');

In other words, the server accepts as "attachmentcontents," a CURL file object. I am thinking that if I can create and equivalent object in java, I would be out of the woods. How do I do so? Alternately, what is the equivalent of a CURL file object in java?

Aamir Quraishi
  • 144
  • 1
  • 12
  • 1
    See http://stackoverflow.com/questions/1378920/how-can-i-make-a-multipart-form-data-post-request-using-java – Sualeh Fatehi Dec 16 '16 at 02:00
  • I do not think that the server is accepting multipart/form-data. It seems to be accepting multipart/form which I suspect is a custom type. I did try some other versions of multipart uploads in the event that there is an error in the documentation (they meant multipart/form-data and not multipart/form) which did not work. Still, this is worth a try. – Aamir Quraishi Dec 16 '16 at 02:06
  • 1
    Thanks for the link. Yes, the solutions given on those link worked for me! – Aamir Quraishi Dec 16 '16 at 06:54

0 Answers0