Docusign REST API:将文档下载到字符串 [英] Docusign REST API: Downloading document to string

查看:88
本文介绍了Docusign REST API:将文档下载到字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用docusign API和PHP构建应用程序。除无法弄清楚如何下载文档外,我已经完成了大部分工作。我一直在该网站和Docusign网站上进行搜索。 Docusign有一个此处的示例,它显示了如何获取PHP中的文档列表,但是下载没有PHP示例。他们在Docusign REST API文档中解释了此处的方法。但这表示响应为 PDF文件。

I am building an app using the docusign API and PHP. I have most of this working except I cannot figure out how to download the document. I have been searching on this site and on the Docusign site. Docusign has an example here, that shows how to get a list of docs in PHP, but the downloading does not have a PHP example. In the Docusign REST API docs they explain the method here. But this says the response is "PDF File".

在下面的示例代码中,我试图将内容放入文件中,但是它创建了一个空文件。如果我print_r($ data),我得到这个:

In my sample code below, I have tried to put the contents into a file, but it creates and empty file. If I print_r($data), I get this:

      SplFileObject Object
(
    [pathName:SplFileInfo:private] => /tmp/419ULk
    [fileName:SplFileInfo:private] => 419ULk
    [openMode:SplFileObject:private] => w
    [delimiter:SplFileObject:private] => ,
    [enclosure:SplFileObject:private] => "
)

它确实在/ tmp中创建了文件,但我想将文档保留在字符串中,以便将其发送或保存到数据库。

It does create the file in /tmp, but I want to keep the document in a string so I send or save to DB.

这是我的控制器函数:

public function get_document($envelopeId, $cert = FALSE)
{
    $save_dir = BASEPATH."../documents/";
    if ($envelopeId) {
        $this->load->model('docusign_model');
        $data = $this->docusign_model->get_document($envelopeId, $cert);
    }
    file_put_contents($save_dir.$envelopeId.".pdf", $data);
    //print_r($data);
    die("116");
}

这在docusign_model中:

This is in docusign_model:

public function get_document($envelopeId, $cert)
    {
        $docuSignAuth = $this->auth();
        if ($docuSignAuth) {
            $envelopeApi = new EnvelopesApi($docuSignAuth->apiClient);
            $options = new GetDocumentOptions();
            if($cert) {
                $options->setCertificate(TRUE);
            } else {
                $options->setCertificate(FALSE);
            }
            return $envelopeApi->getDocument($docuSignAuth->accountId, 1, $envelopeId, $options);
        }
        return false;
    }

如何获取此文档并将其保存在字符串中?

How can I get this document and keep it in a string?

任何帮助都将不胜感激!

Any and all help is greatly appreciated!

推荐答案

文件,您必须读取临时文件并将其保存到所需文件

The content comes back as a file, you have to read the temp file and save that to the desired file

使用 file_get_contents 的快速摘要 file_put_contents

$docStream = $envelopeApi->getDocument($accountId, 1, $envelopeId);
file_put_contents("my_document.pdf", file_get_contents($docStream->getPathname()));






更多信息 DocuSign REST API: :EnvelopeDocuments:在以PDF文件格式获取单个文档

这篇关于Docusign REST API:将文档下载到字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆