Very basic stuff - how do I send a document to doc

2019-07-20 00:58发布

Can you tell me whether my code below is fine?

--MYBOUNDARY
Content-Type: application/pdf
Content-Disposition: file; filename="sample.pdf";documentid=1

{ 
[B@17f7be7b
}
--MYBOUNDARY--

The [B@17f7be7b is the byteArray returned by java for my pdf (pdf file with just "Just a sample" as content). I just converted that byteArray to String and I have pasted it here. I get

  "errorCode": "UNABLE_TO_LOAD_DOCUMENT",
  "message": "Unable to load the document. Unable to load Document(1). Error: the document is          corrupt, rebuilding failed"

Pls help me with the right way of doing this.

标签: docusignapi
2条回答
看我几分像从前
2楼-- · 2019-07-20 01:29

You haven't posted the relevant code which makes it harder to debug, but on the surface there are at least two problems with the text you've posted. One is that the document bytes should not be enclosed with brackets { }.

Next it does not look like you are encoding the document bytes correctly. The PDF raw bytes will not start with [B@1.......... Without seeing your code I can only say you need to review how you are writing the PDF bytes to the request.

The reason why so many posts show "Document Bytes Go Here" is that it's pretty useless having a bunch of random, non-human readable characters in the sample request. If you are programmer and you understand what it means to write document bytes to a stream then you should understand no problem. Here is a sample request with once again the document bytes omitted:

POST https://demo.docusign.net/restapi/v2/accounts/123456/envelopes HTTP/1.1

X-DocuSign-Authentication: {"Username":"USERNAME","Password":"PASSWORD","IntegratorKey":"INTEGRATOR_KEY"}
Content-Type: multipart/form-data; boundary=BOUNDARY
Accept: application/json
Host: demo.docusign.net
Content-Length: 23414
Expect: 100-continue
Connection: Keep-Alive

--BOUNDARY
Content-Type: application/json
Content-Disposition: form-data

{
    "status": "sent",
    "emailBlurb": "Test Email Body",
    "emailSubject": "Test Email Subject",
    "documents": [
        {
            "name": "test.pdf",
            "documentId": "1",
            "order": "1"
        }
    ],
    "recipients": {
        "signers": [
            {
                "email": "test@domain.com ",
                "name": "John Doe",
                "recipientId": "1",
                "tabs": {
                    "signHereTabs": [
                        {
                            "xPosition": "100",
                            "yPosition": "100",
                            "documentId": "1",
                            "pageNumber": "1"
                        }
                    ]
                }
            }
        ]
    }
}

--BOUNDARY
Content-Type: application/pdf
Content-Disposition: file; filename="document.pdf"; documentid="1"

[document bytes removed]

--BOUNDARY--

The above request will send a signature request with one recipient of type signer and will place one signature tab on the document for them at location 100 pixels to the right and 100 pixels down from the top left of the document. Check out the DocuSign API Walkthroughs for code samples on how to accomplish this, in particular the 4th walkthrough Request Signature on a Document shows you exactly how to do this in 6 different languages (PHP, Javascript, Java, C#, Python, Objective-C) with instructions:

http://iodocs.docusign.com/APIWalkthroughs

查看更多
贼婆χ
3楼-- · 2019-07-20 01:45

A few comments regarding format/contents of what you posted in your Question:

  • The byte stream should not be surrounded with braces in the request. i.e., remove { and }
  • DO NOT convert the byte stream to String before adding it to the DocuSign request -- the byte stream should be written directly into the request.
  • Where you have [B@17f7be7b the request should instead include the complete and un-encoded *byte stream* for the file (NOT the String that represents the byte stream, but rather, the byte stream itself). The value you posted in your question is way too short to be a valid/complete byte stream for a PDF file.
查看更多
登录 后发表回答