How to upload image file to Stripe from Amazon S3 using Laravel 5.5 and Intervention Image

fronzee

Laravel 5.5 app. I need to retrieve images of driver's licenses from Amazon S3 (already working) and then upload it to Stripe using their api for identity verification (not working).

Stripe's documents give this example:

\Stripe\Stripe::setApiKey(PLATFORM_SECRET_KEY);
\Stripe\FileUpload::create(
    array(
        "purpose" => "identity_document",
        "file" => fopen('/path/to/a/file.jpg', 'r')
    ),
    array("stripe_account" => CONNECTED_STRIPE_ACCOUNT_ID)
);

However, I am not retrieving my files using fopen(). When I retrieve my image from Amazon S3 (using my own custom methods), I end up with an instance of Intervention\Image -- essentially, Image::make($imageFromS3) -- and I don't know how to convert this to the equivalent of the call to fopen('/path/to/a/file.jpg', 'r'). I have tried the following:

$image->stream()

$image->stream()->__toString()

$image->stream('data-url')

$image->stream('data-url')->__toString()

I have also tried skipping intervention image and just using Laravel's storage retrieval, for example:

$image = Storage::disk('s3')->get('path/to/file.jpg');

All of these approaches result in getting an Invalid hash exception from Stripe.

What is the proper way to get a file from S3 and convert it to the equivalent of the fopen() call?

GuySMiLEZ

If the file on S3 is public, you could just pass the URL to Stripe:

\Stripe\FileUpload::create(
    array(
        "purpose" => "identity_document",
        "file" => fopen(Storage::disk('s3')->url($file)),
    ),
    array("stripe_account" => CONNECTED_STRIPE_ACCOUNT_ID)
);

Note that this requires allow_url_fopen to be turned on in your php.ini file.

If not, then you could grab the file from S3 first, write it to a temporary file, and then use the fopen() method that the Stripe documentation speaks of:

// Retrieve file from S3...
$image = Storage::disk('s3')->get($file);

// Create temporary file with image content...
$tmp = tmpfile();
fwrite($tmp, $image);

// Reset file pointer to first byte so that we can read from it from the beginning...
fseek($tmp, 0);

// Upload temporary file to S3...
\Stripe\FileUpload::create(
    array(
        "purpose" => "identity_document",
        "file" => $tmp
    ),
    array("stripe_account" => CONNECTED_STRIPE_ACCOUNT_ID)
);

// Close temporary file and remove it...
fclose($tmp);

See https://secure.php.net/manual/en/function.tmpfile.php for more information.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Laravel 5 - Image Upload and Resize using Intervention Image Package

From Dev

Laravel 5 intervention image upload multiple size

From Dev

Upload file to amazon s3 server using laravel 5

From Dev

Angular 4/5 file upload or image upload to Amazon S3

From Dev

Image Validation in Laravel 5 Intervention

From Dev

Laravel Upload Image to Amazon s3

From Dev

Using intervention/image for upload /resizing with Laravel API

From Dev

How to delete image with Intervention.io library for Laravel 5

From Dev

Saving Intervention Image In Owners Folder in Laravel 5

From Dev

Laravel 5 Class 'Intervention\Image\ImageServiceProvider' not found

From Dev

Add white space to image using Laravel 5 intervention image to make square image

From Dev

Laravel 5 Ajax File/Image Upload

From Dev

How shall I send an image file in body of Http POST request in along with other form data angular 5. Backend is using Intervention package in Laravel

From PHP

Intervention image multiple image upload in laravel

From Dev

How to upload >5GB file using multipart API of S3 right from the browser?

From Dev

Upload Image to Amazon S3 Using Swift3

From Dev

CKeditor 5 with Laravel image upload

From Dev

upload image and access laravel 5

From Dev

Amazon AWS s3 upload using image content - PHP

From Dev

Get image from URL and upload to Amazon S3

From Dev

Upload image to amazon s3 directly from browser - using angular js

From Dev

Amazon S3 upload image - using angular js directly from browser

From Dev

Using Image Intervention with Laravel Nova

From Dev

Laravel 5: Intervention Image, imagecache. Missing argument 2 error

From Dev

Can't write image data laravel 5 Intervention

From Dev

Show Upload Progress for Image Upload to Amazon S3 using Swift 3 and Amazon SDK

From Dev

How upload Image on stripe?

From Dev

How to upload a simple image from a mobile device using expo image picker to AWS S3?

From Dev

Amazon S3 - Carrierwave Image Upload

Related Related

  1. 1

    Laravel 5 - Image Upload and Resize using Intervention Image Package

  2. 2

    Laravel 5 intervention image upload multiple size

  3. 3

    Upload file to amazon s3 server using laravel 5

  4. 4

    Angular 4/5 file upload or image upload to Amazon S3

  5. 5

    Image Validation in Laravel 5 Intervention

  6. 6

    Laravel Upload Image to Amazon s3

  7. 7

    Using intervention/image for upload /resizing with Laravel API

  8. 8

    How to delete image with Intervention.io library for Laravel 5

  9. 9

    Saving Intervention Image In Owners Folder in Laravel 5

  10. 10

    Laravel 5 Class 'Intervention\Image\ImageServiceProvider' not found

  11. 11

    Add white space to image using Laravel 5 intervention image to make square image

  12. 12

    Laravel 5 Ajax File/Image Upload

  13. 13

    How shall I send an image file in body of Http POST request in along with other form data angular 5. Backend is using Intervention package in Laravel

  14. 14

    Intervention image multiple image upload in laravel

  15. 15

    How to upload >5GB file using multipart API of S3 right from the browser?

  16. 16

    Upload Image to Amazon S3 Using Swift3

  17. 17

    CKeditor 5 with Laravel image upload

  18. 18

    upload image and access laravel 5

  19. 19

    Amazon AWS s3 upload using image content - PHP

  20. 20

    Get image from URL and upload to Amazon S3

  21. 21

    Upload image to amazon s3 directly from browser - using angular js

  22. 22

    Amazon S3 upload image - using angular js directly from browser

  23. 23

    Using Image Intervention with Laravel Nova

  24. 24

    Laravel 5: Intervention Image, imagecache. Missing argument 2 error

  25. 25

    Can't write image data laravel 5 Intervention

  26. 26

    Show Upload Progress for Image Upload to Amazon S3 using Swift 3 and Amazon SDK

  27. 27

    How upload Image on stripe?

  28. 28

    How to upload a simple image from a mobile device using expo image picker to AWS S3?

  29. 29

    Amazon S3 - Carrierwave Image Upload

HotTag

Archive