Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MultipartStream usage in uploadTransientDocument() method. #1

Closed
trip-somers opened this issue Nov 29, 2016 · 8 comments
Closed

MultipartStream usage in uploadTransientDocument() method. #1

trip-somers opened this issue Nov 29, 2016 · 8 comments

Comments

@trip-somers
Copy link

trip-somers commented Nov 29, 2016

I have tried a bunch of ways to get this to work using a file system file and nothing seems to work. Guzzle is short on documentation for this, but here's what I've tried:

        $multipart_stream   = new Psr7\MultipartStream([
            [
                'name'     => 'File',
                'contents' => Psr7\stream_for(file_get_contents($filepath))
            ]
        ]);

        $transient_document = $AdobeSign->uploadTransientDocument($multipart_stream);

As far as I can tell, that looks correct, but I get BAD_REQUEST response code.

Can you point me in the right direction?

@trip-somers
Copy link
Author

I was able to get this to work using the example here: https://github.com/guzzle/psr7/blob/master/tests/MultipartStreamTest.php#L97

@adrienthiery
Copy link

adrienthiery commented Dec 14, 2016

Hey @trip-somers,

Getting the same kind of issue here. Could you post the complete example of how you create the MultipartStream and call uploadTransientDocument in the end please?

Thanks a lot!

@trip-somers
Copy link
Author

Here is my full solution:

$file_stream = Psr7\FnStream::decorate(Psr7\stream_for(file_get_contents($filepath)), [
    'getMetadata' => function() use ($filepath) {
        return $filepath;
    }
]);

$multipart_stream   = new Psr7\MultipartStream([
    [
        'name'     => 'File',
        'contents' => $file_stream
    ]
]);

$transient_document = $this->api->uploadTransientDocument($multipart_stream);

My method call is inside a service class in which $this->api points to the main API class in this project.

NOTE: I can't remember if this is related to the uploadTransientDocument() problems I had, but you will likely also have to update the API's parseResponse() method. A few (or several, depending on your usage/perspective) API calls return a response code of 'OK' or something like 'ALREADY_DISABLED'. The distribution version of this method throws an exception for any response code that isn't 'INVALID_ACCESS_TOKEN', 'UNSUPPORTED_MEDIA_TYPE', or 'MISSING_REQUIRED_PARAM'. You obviously don't want an exception for 'OK', so you will need to set up some way to handle this.

Here is what I did for that:

protected function parseResponse($res)
{
    $success_codes = ['OK', 'ALREADY_DISABLED'];

    if ( isset($res['code']) && ! in_array($res['code'], $success_codes) )
    {
        // handle other codes and throw exceptions
    }

    return $res;
}

@adrienthiery
Copy link

Thanks so much for the quick and extended response !

I'll look into that a bit later.

@trip-somers
Copy link
Author

No problem. I had to jump into those files again today so your timing was pretty convenient.

@AdrienKuhn
Copy link
Contributor

Hi @trip-somers,

Thank you for the complete solution. It works great on our side!

kevinem pushed a commit that referenced this issue Jan 6, 2017
Add example for transient document upload.
@RAJESH-BM
Copy link

RAJESH-BM commented Jul 14, 2017

Hi @trip-somers

I'm trying to upload a document but it says

Fatal error: Uncaught exception 'KevinEm\AdobeSign\Exceptions\AdobeSignException' with message 'NO_FILE_CONTENT: Must provide file body' in /var/www/html/adobesign/vendor/kevinem/adobe-sign-php/src/AdobeSign.php:88 Stack trace: #0 /var/www/html/adobesign/vendor/kevinem/adobe-sign-php/src/AdobeSign.php(129): KevinEm\AdobeSign\AdobeSign->parseResponse(Array) #1 /var/www/html/adobesign/index.php(50): KevinEm\AdobeSign\AdobeSign->uploadTransientDocument(Object(GuzzleHttp\Psr7\MultipartStream)) #2 {main} thrown in /var/www/html/adobesign/vendor/kevinem/adobe-sign-php/src/AdobeSign.php on line 88

Please help me to solve this.

@bitroger
Copy link

Hello, how I send two documents to sign? for example i have this code
$multipart_stream = new MultipartStream([

        [
            'name' => 'File',
            'contents' => $file_stream
        ],
        [
            'name' => 'Files',
            'contents' => $file_streams
        ]

    ]);

help me please!!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants