docusign / docusign-esign-php-client

The Official Docusign PHP Client Library used to interact with the eSign REST API. Send, sign, and approve documents using this client.
https://www.docusign.com/devcenter
MIT License
198 stars 122 forks source link

cannot get the document from 6.5 version ? #159

Closed mtariqsajid closed 2 years ago

mtariqsajid commented 2 years ago

on 6.4 version the file was save on the php://temp

but on 6.5 version it is saving on the php://memory

how to change it to php://temp

$envelopeApi = new DocuSign\eSign\Api\EnvelopesApi($apiClient);

$temp_file = $envelopeApi->getDocument($args['account_id'], $document_id, $args["envelope_id"]);
ndench commented 2 years ago

Yeah I just got caught by this breaking change too. You can see the change in the PR on ObjectSerializer.

You need to manually write the data to disk:

        $filename = \tempnam(\sys_get_temp_dir(), 'docusign');
        $file     = \fopen($filename, 'wb');

        // Need to rewind to the start, because docusign leaves the filepointer at the end
        $document->rewind();
        while (false === $document->eof()) {
            // Write the file in chunks to avoid memory issues
            $chunk = $document->fread(512);
            \fwrite($file, $chunk);
        }

        \fclose($file);
Eugentis commented 2 years ago

@ndench could you clarify the reason for this modification?

As I can see it is not comfortable to receive file from DS now....

ndench commented 2 years ago

@Eugentis this modification is because the DocuSign client now saves the document in php://memory instead of writing it to disk. The code I posted above is almost exactly the same as the DocuSign client used to do in order to write the file to disk, as you can see in the PR that made the change.

The $document is the \splFileObject returned by DocuSign, it used to point to a file on disk, but now it points to php://memory. So we just read thy bytes from the file object, and write them to disk.