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

[BUG] Export to s3 - CouldNotCreateChecksumException #2156

Closed
3 tasks done
jgodish opened this issue Apr 11, 2019 · 17 comments
Closed
3 tasks done

[BUG] Export to s3 - CouldNotCreateChecksumException #2156

jgodish opened this issue Apr 11, 2019 · 17 comments

Comments

@jgodish
Copy link

jgodish commented Apr 11, 2019

Prerequisites

  • Able to reproduce the behaviour outside of your code, the problem is isolated to Laravel Excel.
  • Checked that your issue isn't already filed.
  • Checked if no PR was submitted that fixes this problem.

Versions

  • PHP version: 7.2.0-1+ubuntu16.04.1+deb.sury.org+1
  • Laravel version: 5.8.10
  • Package version: 3.1.11

Description

Upgrading from laravel 5.7 to 5.8 went through the normal upgrade steps. Got all code in the framework updated based on the laravel docs. Started testing and realized exporting data and storing it in s3 was failing.

Steps to Reproduce

Expected behavior:

The file should be exported and stored in s3 like it is in the previous version before upgrading the framework and laravel excel

Actual behavior:

The exception occurs with queuing and regular "store" methods.
I get the following error:

A sha256 checksum could not be calculated for the provided upload body, because it was not seekable. To prevent this error you can either 1) include the ContentMD5 or ContentSHA256 parameters with your request, 2) use a seekable stream for the body, or 3) wrap the non-seekable stream in a GuzzleHttp\Psr7\CachingStream object. You should be careful though and remember that the CachingStream utilizes PHP temp streams. This means that the stream will be temporarily stored on the local disk.

(2/2) CouldNotCreateChecksumException A sha256 checksum could not be calculated for the provided upload body, because it was not seekable. To prevent this error you can either 1) include the ContentMD5 or ContentSHA256 parameters with your request, 2) use a seekable stream for the body, or 3) wrap the non-seekable stream in a GuzzleHttp\Psr7\CachingStream object. You should be careful though and remember that the CachingStream utilizes PHP temp streams. This means that the stream will be temporarily stored on the local disk.
in SignatureV4.php line 166
at SignatureV4->getPayload(object(Request))in S3SignatureV4.php line 22
at S3SignatureV4->signRequest(object(Request), object(Credentials))in Middleware.php line 126
at Middleware::Aws{closure}(object(Credentials))in FulfilledPromise.php line 39
at FulfilledPromise::GuzzleHttp\Promise{closure}()in TaskQueue.php line 47
at TaskQueue->run(true)in Promise.php line 246
at Promise->invokeWaitFn()in Promise.php line 223
at Promise->waitIfPending()in Promise.php line 267
at Promise->invokeWaitList()in Promise.php line 225
at Promise->waitIfPending()in Promise.php line 62
at Promise->wait()in S3ClientTrait.php line 33
at S3Client->upload('mobiniti-uploads', 'exports/local/Greyght-unsubscribes-2014-07-10-to-2019-04-11.csv', resource, 'public-read', array('params' =>array('visibility' => 'public', 'ACL' => 'public-read', 'ContentType' => 'text/x-comma-separated-values', 'ContentLength' => 172)))in AwsS3Adapter.php line 596
at AwsS3Adapter->upload('exports/local/Greyght-unsubscribes-2014-07-10-to-2019-04-11.csv', resource, object(Config))in AwsS3Adapter.php line 380
at AwsS3Adapter->writeStream('exports/local/Greyght-unsubscribes-2014-07-10-to-2019-04-11.csv', resource, object(Config))in Filesystem.php line 122
at Filesystem->putStream('exports/local/Greyght-unsubscribes-2014-07-10-to-2019-04-11.csv', resource, object(Config))in FilesystemAdapter.php line 194
at FilesystemAdapter->put('exports/local/Greyght-unsubscribes-2014-07-10-to-2019-04-11.csv', resource, array())in Disk.php line 61
at Disk->put('exports/local/Greyght-unsubscribes-2014-07-10-to-2019-04-11.csv', resource)in Disk.php line 82
at Disk->copy(object(LocalTemporaryFile), 'exports/local/Greyght-unsubscribes-2014-07-10-to-2019-04-11.csv')in Excel.php line 102
at Excel->store(object(Unsubscribes), 'exports/local/Greyght-unsubscribes-2014-07-10-to-2019-04-11.csv', 's3', 'Csv', array())in Exportable.php line 52
at Unsubscribes->store('exports/local/Greyght-unsubscribes-2014-07-10-to-2019-04-11.csv', 's3', 'Csv')in Export.php line 72
at Export->exportUnsubscribes()in DashboardController.php line 270
at DashboardController->exportUnsubscribes()
at call_user_func_array(array(object(DashboardController), 'exportUnsubscribes'), array())in Controller.php line 54
at Controller->callAction('exportUnsubscribes', array())in ControllerDispatcher.php line 45
at ControllerDispatcher->dispatch(object(Route), object(DashboardController), 'exportUnsubscribes')in Route.php line 219
at Route->runController()in Route.php line 176
at Route->run()in Router.php line 680
at Router->Illuminate\Routing{closure}(object(Request))in Pipeline.php line 30
at Pipeline->Illuminate\Routing{closure}(object(Request))in MainController.php line 49
at MainController->App\Http\Controllers\App{closure}(object(Request), object(Closure))in Pipeline.php line 145
at Pipeline->Illuminate\Pipeline{closure}(object(Request))in Pipeline.php line 53
at Pipeline->Illuminate\Routing{closure}(object(Request))in VerifyCsrfToken.php line 22
at VerifyCsrfToken->handle(object(Request), object(Closure))in Pipeline.php line 163
at Pipeline->Illuminate\Pipeline{closure}(object(Request))in Pipeline.php line 53
at Pipeline->Illuminate\Routing{closure}(object(Request))in AppAuthentication.php line 61
at AppAuthentication->handle(object(Request), object(Closure))in Pipeline.php line 163
at Pipeline->Illuminate\Pipeline{closure}(object(Request))in Pipeline.php line 53
at Pipeline->Illuminate\Routing{closure}(object(Request))in TrustProxies.php line 57
at TrustProxies->handle(object(Request), object(Closure))in Pipeline.php line 163
at Pipeline->Illuminate\Pipeline{closure}(object(Request))in Pipeline.php line 53
at Pipeline->Illuminate\Routing{closure}(object(Request))in AccountHostnameMiddleware.php line 21
at AccountHostnameMiddleware->handle(object(Request), object(Closure))in Pipeline.php line 163
at Pipeline->Illuminate\Pipeline{closure}(object(Request))in Pipeline.php line 53
at Pipeline->Illuminate\Routing{closure}(object(Request))in CreateFreshApiToken.php line 50
at CreateFreshApiToken->handle(object(Request), object(Closure))in Pipeline.php line 163
at Pipeline->Illuminate\Pipeline{closure}(object(Request))in Pipeline.php line 53
at Pipeline->Illuminate\Routing{closure}(object(Request))in SubstituteBindings.php line 41
at SubstituteBindings->handle(object(Request), object(Closure))in Pipeline.php line 163
at Pipeline->Illuminate\Pipeline{closure}(object(Request))in Pipeline.php line 53
at Pipeline->Illuminate\Routing{closure}(object(Request))in AuthenticateSession.php line 58
at AuthenticateSession->handle(object(Request), object(Closure))in Pipeline.php line 163
at Pipeline->Illuminate\Pipeline{closure}(object(Request))in Pipeline.php line 53
at Pipeline->Illuminate\Routing{closure}(object(Request))in ShareErrorsFromSession.php line 49
at ShareErrorsFromSession->handle(object(Request), object(Closure))in Pipeline.php line 163
at Pipeline->Illuminate\Pipeline{closure}(object(Request))in Pipeline.php line 53
at Pipeline->Illuminate\Routing{closure}(object(Request))in StartSession.php line 56
at StartSession->handle(object(Request), object(Closure))in Pipeline.php line 163
at Pipeline->Illuminate\Pipeline{closure}(object(Request))in Pipeline.php line 53
at Pipeline->Illuminate\Routing{closure}(object(Request))in AddQueuedCookiesToResponse.php line 37
at AddQueuedCookiesToResponse->handle(object(Request), object(Closure))in Pipeline.php line 163
at Pipeline->Illuminate\Pipeline{closure}(object(Request))in Pipeline.php line 53
at Pipeline->Illuminate\Routing{closure}(object(Request))in EncryptCookies.php line 66
at EncryptCookies->handle(object(Request), object(Closure))in Pipeline.php line 163
at Pipeline->Illuminate\Pipeline{closure}(object(Request))in Pipeline.php line 53
at Pipeline->Illuminate\Routing{closure}(object(Request))in Pipeline.php line 104
at Pipeline->then(object(Closure))in Router.php line 682
at Router->runRouteWithinStack(object(Route), object(Request))in Router.php line 657
at Router->runRoute(object(Request), object(Route))in Router.php line 623
at Router->dispatchToRoute(object(Request))in Router.php line 612
at Router->dispatch(object(Request))in Kernel.php line 176
at Kernel->Illuminate\Foundation\Http{closure}(object(Request))in Pipeline.php line 30
at Pipeline->Illuminate\Routing{closure}(object(Request))in ServeNova.php line 26
at ServeNova->handle(object(Request), object(Closure))in Pipeline.php line 163
at Pipeline->Illuminate\Pipeline{closure}(object(Request))in Pipeline.php line 53
at Pipeline->Illuminate\Routing{closure}(object(Request))in InjectDebugbar.php line 58
at InjectDebugbar->handle(object(Request), object(Closure))in Pipeline.php line 163
at Pipeline->Illuminate\Pipeline{closure}(object(Request))in Pipeline.php line 53
at Pipeline->Illuminate\Routing{closure}(object(Request))in CheckForMaintenanceMode.php line 62
at CheckForMaintenanceMode->handle(object(Request), object(Closure))in Pipeline.php line 163
at Pipeline->Illuminate\Pipeline{closure}(object(Request))in Pipeline.php line 53
at Pipeline->Illuminate\Routing{closure}(object(Request))in Pipeline.php line 104
at Pipeline->then(object(Closure))in Kernel.php line 151
at Kernel->sendRequestThroughRouter(object(Request))in Kernel.php line 116
at Kernel->handle(object(Request))in index.php line 52

(1/2) RuntimeExceptionCannot read from non-readable stream
in Stream.php line 208
at Stream->read(1048576)in functions.php line 419
at GuzzleHttp\Psr7\hash(object(Stream), 'sha256')in SignatureV4.php line 164
at SignatureV4->getPayload(object(Request))in S3SignatureV4.php line 22
at S3SignatureV4->signRequest(object(Request), object(Credentials))in Middleware.php line 126
at Middleware::Aws{closure}(object(Credentials))in FulfilledPromise.php line 39
at FulfilledPromise::GuzzleHttp\Promise{closure}()in TaskQueue.php line 47
at TaskQueue->run(true)in Promise.php line 246
at Promise->invokeWaitFn()in Promise.php line 223
at Promise->waitIfPending()in Promise.php line 267
at Promise->invokeWaitList()in Promise.php line 225
at Promise->waitIfPending()in Promise.php line 62
at Promise->wait()in S3ClientTrait.php line 33
at S3Client->upload('mobiniti-uploads', 'exports/local/Greyght-unsubscribes-2014-07-10-to-2019-04-11.csv', resource, 'public-read', array('params' =>array('visibility' => 'public', 'ACL' => 'public-read', 'ContentType' => 'text/x-comma-separated-values', 'ContentLength' => 172)))in AwsS3Adapter.php line 596
at AwsS3Adapter->upload('exports/local/Greyght-unsubscribes-2014-07-10-to-2019-04-11.csv', resource, object(Config))in AwsS3Adapter.php line 380
at AwsS3Adapter->writeStream('exports/local/Greyght-unsubscribes-2014-07-10-to-2019-04-11.csv', resource, object(Config))in Filesystem.php line 122
at Filesystem->putStream('exports/local/Greyght-unsubscribes-2014-07-10-to-2019-04-11.csv', resource, object(Config))in FilesystemAdapter.php line 194
at FilesystemAdapter->put('exports/local/Greyght-unsubscribes-2014-07-10-to-2019-04-11.csv', resource, array())in Disk.php line 61
at Disk->put('exports/local/Greyght-unsubscribes-2014-07-10-to-2019-04-11.csv', resource)in Disk.php line 82
at Disk->copy(object(LocalTemporaryFile), 'exports/local/Greyght-unsubscribes-2014-07-10-to-2019-04-11.csv')in Excel.php line 102
at Excel->store(object(Unsubscribes), 'exports/local/Greyght-unsubscribes-2014-07-10-to-2019-04-11.csv', 's3', 'Csv', array())in Exportable.php line 52
at Unsubscribes->store('exports/local/Greyght-unsubscribes-2014-07-10-to-2019-04-11.csv', 's3', 'Csv')in Export.php line 72
at Export->exportUnsubscribes()in DashboardController.php line 270
at DashboardController->exportUnsubscribes()
at call_user_func_array(array(object(DashboardController), 'exportUnsubscribes'), array())in Controller.php line 54
at Controller->callAction('exportUnsubscribes', array())in ControllerDispatcher.php line 45
at ControllerDispatcher->dispatch(object(Route), object(DashboardController), 'exportUnsubscribes')in Route.php line 219
at Route->runController()in Route.php line 176
at Route->run()in Router.php line 680
at Router->Illuminate\Routing{closure}(object(Request))in Pipeline.php line 30
at Pipeline->Illuminate\Routing{closure}(object(Request))in MainController.php line 49
at MainController->App\Http\Controllers\App{closure}(object(Request), object(Closure))in Pipeline.php line 145
at Pipeline->Illuminate\Pipeline{closure}(object(Request))in Pipeline.php line 53
at Pipeline->Illuminate\Routing{closure}(object(Request))in VerifyCsrfToken.php line 22
at VerifyCsrfToken->handle(object(Request), object(Closure))in Pipeline.php line 163
at Pipeline->Illuminate\Pipeline{closure}(object(Request))in Pipeline.php line 53
at Pipeline->Illuminate\Routing{closure}(object(Request))in AppAuthentication.php line 61
at AppAuthentication->handle(object(Request), object(Closure))in Pipeline.php line 163
at Pipeline->Illuminate\Pipeline{closure}(object(Request))in Pipeline.php line 53
at Pipeline->Illuminate\Routing{closure}(object(Request))in TrustProxies.php line 57
at TrustProxies->handle(object(Request), object(Closure))in Pipeline.php line 163
at Pipeline->Illuminate\Pipeline{closure}(object(Request))in Pipeline.php line 53
at Pipeline->Illuminate\Routing{closure}(object(Request))in AccountHostnameMiddleware.php line 21
at AccountHostnameMiddleware->handle(object(Request), object(Closure))in Pipeline.php line 163
at Pipeline->Illuminate\Pipeline{closure}(object(Request))in Pipeline.php line 53
at Pipeline->Illuminate\Routing{closure}(object(Request))in CreateFreshApiToken.php line 50
at CreateFreshApiToken->handle(object(Request), object(Closure))in Pipeline.php line 163
at Pipeline->Illuminate\Pipeline{closure}(object(Request))in Pipeline.php line 53
at Pipeline->Illuminate\Routing{closure}(object(Request))in SubstituteBindings.php line 41
at SubstituteBindings->handle(object(Request), object(Closure))in Pipeline.php line 163
at Pipeline->Illuminate\Pipeline{closure}(object(Request))in Pipeline.php line 53
at Pipeline->Illuminate\Routing{closure}(object(Request))in AuthenticateSession.php line 58
at AuthenticateSession->handle(object(Request), object(Closure))in Pipeline.php line 163
at Pipeline->Illuminate\Pipeline{closure}(object(Request))in Pipeline.php line 53
at Pipeline->Illuminate\Routing{closure}(object(Request))in ShareErrorsFromSession.php line 49
at ShareErrorsFromSession->handle(object(Request), object(Closure))in Pipeline.php line 163
at Pipeline->Illuminate\Pipeline{closure}(object(Request))in Pipeline.php line 53
at Pipeline->Illuminate\Routing{closure}(object(Request))in StartSession.php line 56
at StartSession->handle(object(Request), object(Closure))in Pipeline.php line 163
at Pipeline->Illuminate\Pipeline{closure}(object(Request))in Pipeline.php line 53
at Pipeline->Illuminate\Routing{closure}(object(Request))in AddQueuedCookiesToResponse.php line 37
at AddQueuedCookiesToResponse->handle(object(Request), object(Closure))in Pipeline.php line 163
at Pipeline->Illuminate\Pipeline{closure}(object(Request))in Pipeline.php line 53
at Pipeline->Illuminate\Routing{closure}(object(Request))in EncryptCookies.php line 66
at EncryptCookies->handle(object(Request), object(Closure))in Pipeline.php line 163
at Pipeline->Illuminate\Pipeline{closure}(object(Request))in Pipeline.php line 53
at Pipeline->Illuminate\Routing{closure}(object(Request))in Pipeline.php line 104
at Pipeline->then(object(Closure))in Router.php line 682
at Router->runRouteWithinStack(object(Route), object(Request))in Router.php line 657
at Router->runRoute(object(Request), object(Route))in Router.php line 623
at Router->dispatchToRoute(object(Request))in Router.php line 612
at Router->dispatch(object(Request))in Kernel.php line 176
at Kernel->Illuminate\Foundation\Http{closure}(object(Request))in Pipeline.php line 30
at Pipeline->Illuminate\Routing{closure}(object(Request))in ServeNova.php line 26
at ServeNova->handle(object(Request), object(Closure))in Pipeline.php line 163
at Pipeline->Illuminate\Pipeline{closure}(object(Request))in Pipeline.php line 53
at Pipeline->Illuminate\Routing{closure}(object(Request))in InjectDebugbar.php line 58
at InjectDebugbar->handle(object(Request), object(Closure))in Pipeline.php line 163
at Pipeline->Illuminate\Pipeline{closure}(object(Request))in Pipeline.php line 53
at Pipeline->Illuminate\Routing{closure}(object(Request))in CheckForMaintenanceMode.php line 62
at CheckForMaintenanceMode->handle(object(Request), object(Closure))in Pipeline.php line 163
at Pipeline->Illuminate\Pipeline{closure}(object(Request))in Pipeline.php line 53
at Pipeline->Illuminate\Routing{closure}(object(Request))in Pipeline.php line 104
at Pipeline->then(object(Closure))in Kernel.php line 151
at Kernel->sendRequestThroughRouter(object(Request))in Kernel.php line 116
at Kernel->handle(object(Request))in index.php line 52

Additional Information

I have 2 instances of our application so I tested this on the 5.7 version to see if there was something configured wrong on my local environment but the same export worked as expected so it appears to be an issue with the upgrade. The previous version of laravel excel was 3.1.6 (I don't believe I missed anything with upgrading to 3.1.11).

I tried changing the excel config file for exports.csv to use "\r\n" for the line ending setting but that didn't change the behavior any.

Then I tried viewing the contents of the file by doing a dd right before the exception is thrown in SignatureV4 and I was able to read the contents fine (from the dump statement) so it seems it's related to the Psr7\hash function. The 1/2 exception shows "Cannot read from non-readable stream" and when I dumped the data for $request->getBody() it shows readable as false. I'm not sure how/why this happens but it seems to be related to the overall issue.
Stream {#25561 ▼
-stream: stream resource @59
timed_out: false
blocked: true
eof: false
wrapper_type: "plainfile"
stream_type: "STDIO"
mode: "rb+"
unread_bytes: 0
seekable: true
uri: "/tmp/tmp-laravel-excel/laravel-excel-J374kbEboqVHytyJLIH4MaxiIgp66cri"
options: []
}
-size: 172
-seekable: true
-readable: false
-writable: false
-uri: "/tmp/tmp-laravel-excel/laravel-excel-J374kbEboqVHytyJLIH4MaxiIgp66cri"
-customMetadata: []
}
I am using a custom tmp directory as well

The aws sdk hasn't changed during this upgrade (version 3.64.5 if it helps). I then tried putting a file into s3 with the traditional laravel function and it worked fine so I don't think it's an s3 config issue.

\Illuminate\Support\Facades\Storage::disk('s3')->put('exports/local/test.csv','test,another');

The export class implements FromQuery, WithHeadings, WithMapping
The class is called by doing:

(new Unsubscribes($this->start_date, $this->end_date))->forAccount($this->account)->store($path, 's3', \Maatwebsite\Excel\Excel::CSV); 

I also tried setting the "visibility" option but still got the error.
I tried creating the file using the storage facade thinking it was some weird permission/access thing but the same error occurred.

@jgodish
Copy link
Author

jgodish commented Jun 12, 2019

This issue doesn't appear to happen for version 3.1.7 but does occur in 3.1.8. I see there are quite a few changes between these versions but I can't seem to narrow down what specifically is causing the issue.

@GlennM
Copy link
Contributor

GlennM commented Jun 13, 2019

This issue doesn't appear to happen for version 3.1.7 but does occur in 3.1.8. I see there are quite a few changes between these versions but I can't seem to narrow down what specifically is causing the issue.

Could you try as well on the latest available version? Currently, that's 3.1.13. Thanks!

@jgodish
Copy link
Author

jgodish commented Jun 13, 2019

I just tried it with version 3.1.13 and received the same error. I put the stack trace below as well in case it could help in some way.

[2019-06-13 12:42:28] local.ERROR: A sha256 checksum could not be calculated for the provided upload body, because it was not seekable. To prevent this error you can either 1) include the ContentMD5 or ContentSHA256 parameters with your request, 2) use a seekable stream for the body, or 3) wrap the non-seekable stream in a GuzzleHttp\Psr7\CachingStream object. You should be careful though and remember that the CachingStream utilizes PHP temp streams. This means that the stream will be temporarily stored on the local disk. {"userId":2,"exception":"[object] (Aws\Exception\CouldNotCreateChecksumException(code: 0): A sha256 checksum could not be calculated for the provided upload body, because it was not seekable. To prevent this error you can either 1) include the ContentMD5 or ContentSHA256 parameters with your request, 2) use a seekable stream for the body, or 3) wrap the non-seekable stream in a GuzzleHttp\Psr7\CachingStream object. You should be careful though and remember that the CachingStream utilizes PHP temp streams. This means that the stream will be temporarily stored on the local disk. at /home/vagrant/Code/mobiniti/sms-app/vendor/aws/aws-sdk-php/src/Signature/SignatureV4.php:166, RuntimeException(code: 0): Cannot read from non-readable stream at /home/vagrant/Code/mobiniti/sms-app/vendor/guzzlehttp/psr7/src/Stream.php:208)
[stacktrace]
0 /home/vagrant/Code/mobiniti/sms-app/vendor/aws/aws-sdk-php/src/Signature/S3SignatureV4.php(22): Aws\Signature\SignatureV4->getPayload(Object(GuzzleHttp\Psr7\Request))
1 /home/vagrant/Code/mobiniti/sms-app/vendor/aws/aws-sdk-php/src/Middleware.php(126): Aws\Signature\S3SignatureV4->signRequest(Object(GuzzleHttp\Psr7\Request), Object(Aws\Credentials\Credentials))
2 /home/vagrant/Code/mobiniti/sms-app/vendor/guzzlehttp/promises/src/FulfilledPromise.php(39): Aws\Middleware::Aws\{closure}(Object(Aws\Credentials\Credentials))
3 /home/vagrant/Code/mobiniti/sms-app/vendor/guzzlehttp/promises/src/TaskQueue.php(47): GuzzleHttp\Promise\FulfilledPromise::GuzzleHttp\Promise\{closure}()
4 /home/vagrant/Code/mobiniti/sms-app/vendor/guzzlehttp/promises/src/Promise.php(246): GuzzleHttp\Promise\TaskQueue->run(true)
5 /home/vagrant/Code/mobiniti/sms-app/vendor/guzzlehttp/promises/src/Promise.php(223): GuzzleHttp\Promise\Promise->invokeWaitFn()
6 /home/vagrant/Code/mobiniti/sms-app/vendor/guzzlehttp/promises/src/Promise.php(267): GuzzleHttp\Promise\Promise->waitIfPending()
7 /home/vagrant/Code/mobiniti/sms-app/vendor/guzzlehttp/promises/src/Promise.php(225): GuzzleHttp\Promise\Promise->invokeWaitList()
8 /home/vagrant/Code/mobiniti/sms-app/vendor/guzzlehttp/promises/src/Promise.php(62): GuzzleHttp\Promise\Promise->waitIfPending()
9 /home/vagrant/Code/mobiniti/sms-app/vendor/aws/aws-sdk-php/src/S3/S3ClientTrait.php(33): GuzzleHttp\Promise\Promise->wait()
10 /home/vagrant/Code/mobiniti/sms-app/vendor/league/flysystem-aws-s3-v3/src/AwsS3Adapter.php(596): Aws\S3\S3Client->upload('mobiniti-upload...', 'exports/local/G...', Resource id 76, 'public-read', Array)
11 /home/vagrant/Code/mobiniti/sms-app/vendor/league/flysystem-aws-s3-v3/src/AwsS3Adapter.php(380): League\Flysystem\AwsS3v3\AwsS3Adapter->upload('exports/local/G...', Resource id 76, Object(League\Flysystem\Config))
12 /home/vagrant/Code/mobiniti/sms-app/vendor/league/flysystem/src/Filesystem.php(122): League\Flysystem\AwsS3v3\AwsS3Adapter->writeStream('exports/local/G...', Resource id 76, Object(League\Flysystem\Config))
13 /home/vagrant/Code/mobiniti/sms-app/vendor/laravel/framework/src/Illuminate/Filesystem/FilesystemAdapter.php(194): League\Flysystem\Filesystem->putStream('exports/local/G...', Resource id 76, Object(League\Flysystem\Config))
14 /home/vagrant/Code/mobiniti/sms-app/vendor/maatwebsite/excel/src/Files/Disk.php(61): Illuminate\Filesystem\FilesystemAdapter->put('exports/local/G...', Resource id 76, Array)
15 /home/vagrant/Code/mobiniti/sms-app/vendor/maatwebsite/excel/src/Files/Disk.php(82): Maatwebsite\Excel\Files\Disk->put('exports/local/G...', Resource id 76)
16 /home/vagrant/Code/mobiniti/sms-app/vendor/maatwebsite/excel/src/Excel.php(103): Maatwebsite\Excel\Files\Disk->copy(Object(Maatwebsite\Excel\Files\LocalTemporaryFile), 'exports/local/G...')
17 /home/vagrant/Code/mobiniti/sms-app/vendor/maatwebsite/excel/src/Concerns/Exportable.php(58): Maatwebsite\Excel\Excel->store(Object(App\Exports\Unsubscribes), 'exports/local/G...', 's3', 'Csv', Array)
18 /home/vagrant/Code/mobiniti/sms-app/app/Services/Export.php(72): App\Exports\Unsubscribes->store('exports/local/G...', 's3', 'Csv')
19 /home/vagrant/Code/mobiniti/sms-app/app/Http/Controllers/App/Ajax/DashboardController.php(270): App\Services\Export->exportUnsubscribes()
20 [internal function]: App\Http\Controllers\App\Ajax\DashboardController->exportUnsubscribes()
21 /home/vagrant/Code/mobiniti/sms-app/vendor/laravel/framework/src/Illuminate/Routing/Controller.php(54): call_user_func_array(Array, Array)
22 /home/vagrant/Code/mobiniti/sms-app/vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php(45): Illuminate\Routing\Controller->callAction('exportUnsubscri...', Array)
23 /home/vagrant/Code/mobiniti/sms-app/vendor/laravel/framework/src/Illuminate/Routing/Route.php(219): Illuminate\Routing\ControllerDispatcher->dispatch(Object(Illuminate\Routing\Route), Object(App\Http\Controllers\App\Ajax\DashboardController), 'exportUnsubscri...')
24 /home/vagrant/Code/mobiniti/sms-app/vendor/laravel/framework/src/Illuminate/Routing/Route.php(176): Illuminate\Routing\Route->runController()
25 /home/vagrant/Code/mobiniti/sms-app/vendor/laravel/framework/src/Illuminate/Routing/Router.php(680): Illuminate\Routing\Route->run()
26 /home/vagrant/Code/mobiniti/sms-app/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(30): Illuminate\Routing\Router->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))
27 /home/vagrant/Code/mobiniti/sms-app/app/Http/Controllers/App/MainController.php(49): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))
28 /home/vagrant/Code/mobiniti/sms-app/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(145): App\Http\Controllers\App\MainController->App\Http\Controllers\App\{closure}(Object(Illuminate\Http\Request), Object(Closure))
29 /home/vagrant/Code/mobiniti/sms-app/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
30 /home/vagrant/Code/mobiniti/sms-app/app/Http/Middleware/VerifyCsrfToken.php(22): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))
31 /home/vagrant/Code/mobiniti/sms-app/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(163): App\Http\Middleware\VerifyCsrfToken->handle(Object(Illuminate\Http\Request), Object(Closure))
32 /home/vagrant/Code/mobiniti/sms-app/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
33 /home/vagrant/Code/mobiniti/sms-app/app/Http/Middleware/AppAuthentication.php(61): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))
34 /home/vagrant/Code/mobiniti/sms-app/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(163): App\Http\Middleware\AppAuthentication->handle(Object(Illuminate\Http\Request), Object(Closure))
35 /home/vagrant/Code/mobiniti/sms-app/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
36 /home/vagrant/Code/mobiniti/sms-app/vendor/fideloper/proxy/src/TrustProxies.php(57): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))
37 /home/vagrant/Code/mobiniti/sms-app/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(163): Fideloper\Proxy\TrustProxies->handle(Object(Illuminate\Http\Request), Object(Closure))
38 /home/vagrant/Code/mobiniti/sms-app/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
39 /home/vagrant/Code/mobiniti/sms-app/app/Http/Middleware/AccountHostnameMiddleware.php(21): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))
40 /home/vagrant/Code/mobiniti/sms-app/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(163): App\Http\Middleware\AccountHostnameMiddleware->handle(Object(Illuminate\Http\Request), Object(Closure))
41 /home/vagrant/Code/mobiniti/sms-app/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
42 /home/vagrant/Code/mobiniti/sms-app/vendor/laravel/passport/src/Http/Middleware/CreateFreshApiToken.php(50): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))
43 /home/vagrant/Code/mobiniti/sms-app/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(163): Laravel\Passport\Http\Middleware\CreateFreshApiToken->handle(Object(Illuminate\Http\Request), Object(Closure))
44 /home/vagrant/Code/mobiniti/sms-app/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
45 /home/vagrant/Code/mobiniti/sms-app/vendor/laravel/framework/src/Illuminate/Routing/Middleware/SubstituteBindings.php(41): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))
46 /home/vagrant/Code/mobiniti/sms-app/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(163): Illuminate\Routing\Middleware\SubstituteBindings->handle(Object(Illuminate\Http\Request), Object(Closure))
47 /home/vagrant/Code/mobiniti/sms-app/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
48 /home/vagrant/Code/mobiniti/sms-app/vendor/laravel/framework/src/Illuminate/Session/Middleware/AuthenticateSession.php(58): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))
49 /home/vagrant/Code/mobiniti/sms-app/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(163): Illuminate\Session\Middleware\AuthenticateSession->handle(Object(Illuminate\Http\Request), Object(Closure))
50 /home/vagrant/Code/mobiniti/sms-app/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
51 /home/vagrant/Code/mobiniti/sms-app/vendor/laravel/framework/src/Illuminate/View/Middleware/ShareErrorsFromSession.php(49): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))
52 /home/vagrant/Code/mobiniti/sms-app/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(163): Illuminate\View\Middleware\ShareErrorsFromSession->handle(Object(Illuminate\Http\Request), Object(Closure))
53 /home/vagrant/Code/mobiniti/sms-app/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
54 /home/vagrant/Code/mobiniti/sms-app/vendor/laravel/framework/src/Illuminate/Session/Middleware/StartSession.php(56): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))
55 /home/vagrant/Code/mobiniti/sms-app/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(163): Illuminate\Session\Middleware\StartSession->handle(Object(Illuminate\Http\Request), Object(Closure))
56 /home/vagrant/Code/mobiniti/sms-app/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
57 /home/vagrant/Code/mobiniti/sms-app/vendor/laravel/framework/src/Illuminate/Cookie/Middleware/AddQueuedCookiesToResponse.php(37): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))
58 /home/vagrant/Code/mobiniti/sms-app/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(163): Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse->handle(Object(Illuminate\Http\Request), Object(Closure))
59 /home/vagrant/Code/mobiniti/sms-app/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
60 /home/vagrant/Code/mobiniti/sms-app/vendor/laravel/framework/src/Illuminate/Cookie/Middleware/EncryptCookies.php(66): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))
61 /home/vagrant/Code/mobiniti/sms-app/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(163): Illuminate\Cookie\Middleware\EncryptCookies->handle(Object(Illuminate\Http\Request), Object(Closure))
62 /home/vagrant/Code/mobiniti/sms-app/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
63 /home/vagrant/Code/mobiniti/sms-app/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(104): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))
64 /home/vagrant/Code/mobiniti/sms-app/vendor/laravel/framework/src/Illuminate/Routing/Router.php(682): Illuminate\Pipeline\Pipeline->then(Object(Closure))
65 /home/vagrant/Code/mobiniti/sms-app/vendor/laravel/framework/src/Illuminate/Routing/Router.php(657): Illuminate\Routing\Router->runRouteWithinStack(Object(Illuminate\Routing\Route), Object(Illuminate\Http\Request))
66 /home/vagrant/Code/mobiniti/sms-app/vendor/laravel/framework/src/Illuminate/Routing/Router.php(623): Illuminate\Routing\Router->runRoute(Object(Illuminate\Http\Request), Object(Illuminate\Routing\Route))
67 /home/vagrant/Code/mobiniti/sms-app/vendor/laravel/framework/src/Illuminate/Routing/Router.php(612): Illuminate\Routing\Router->dispatchToRoute(Object(Illuminate\Http\Request))
68 /home/vagrant/Code/mobiniti/sms-app/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(176): Illuminate\Routing\Router->dispatch(Object(Illuminate\Http\Request))
69 /home/vagrant/Code/mobiniti/sms-app/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(30): Illuminate\Foundation\Http\Kernel->Illuminate\Foundation\Http\{closure}(Object(Illuminate\Http\Request))
70 /home/vagrant/Code/mobiniti/sms-app/vendor/laravel/nova/src/Http/Middleware/ServeNova.php(26): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))
71 /home/vagrant/Code/mobiniti/sms-app/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(163): Laravel\Nova\Http\Middleware\ServeNova->handle(Object(Illuminate\Http\Request), Object(Closure))
72 /home/vagrant/Code/mobiniti/sms-app/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
73 /home/vagrant/Code/mobiniti/sms-app/vendor/barryvdh/laravel-debugbar/src/Middleware/InjectDebugbar.php(58): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))
74 /home/vagrant/Code/mobiniti/sms-app/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(163): Barryvdh\Debugbar\Middleware\InjectDebugbar->handle(Object(Illuminate\Http\Request), Object(Closure))
75 /home/vagrant/Code/mobiniti/sms-app/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
76 /home/vagrant/Code/mobiniti/sms-app/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/CheckForMaintenanceMode.php(62): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))
77 /home/vagrant/Code/mobiniti/sms-app/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(163): Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode->handle(Object(Illuminate\Http\Request), Object(Closure))
78 /home/vagrant/Code/mobiniti/sms-app/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
79 /home/vagrant/Code/mobiniti/sms-app/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(104): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))
80 /home/vagrant/Code/mobiniti/sms-app/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(151): Illuminate\Pipeline\Pipeline->then(Object(Closure))
81 /home/vagrant/Code/mobiniti/sms-app/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(116): Illuminate\Foundation\Http\Kernel->sendRequestThroughRouter(Object(Illuminate\Http\Request))
82 /home/vagrant/Code/mobiniti/sms-app/public/index.php(52): Illuminate\Foundation\Http\Kernel->handle(Object(Illuminate\Http\Request))
83 {main}
"}

@GlennM
Copy link
Contributor

GlennM commented Jun 13, 2019

This looks similar:
#1947

@jgodish
Copy link
Author

jgodish commented Jun 14, 2019

Yes I saw that when I was looking for solutions but that appears to be only for imports. In this case, it's happening for exports. I tried uploading an empty file to s3 first

\Storage::disk('s3')->put($path,'');

Then, did the export but I received the same error. I also tried storing the file locally and then calling the export but it didn't get uploaded to s3, it just added data to the local file.

$unsubscribes->forAccount($this->account)->store(storage_path("app/{$path}"), 's3', \Maatwebsite\Excel\Excel::CSV);

I would say queuing the export and trying to upload it s3 after would work but it would need to work with multiple servers so it would defeat the purpose. Maybe i'm missing something though and not handling this properly?

@jgodish
Copy link
Author

jgodish commented Jun 14, 2019

I did some more digging and found what I believe to be the issue, but I can't figure out exactly why it's causing problems.
In src/Files/Disk.php -> copy method when the temporary file is LocalTemporaryFile (not sure if this actually matters, just what I see in my particular scenario) it seems like it does not like "contents" for the put method being a stream resource.
When I change

$success = $this->put($destination, $readStream);

into

$success = $this->put($destination, $source->contents());

It uploads it to s3 without an issue. It also worked with queuing the export as well. I'm sure it was built this way for a reason so not sure how exactly to fix this.

@patrickbrouwers
Copy link
Member

@jgodish according to the docblock of the Filesystem contract, a resource is accepted. It "FilesystemAdapter" it checks if's a stream and if so it will call the putStream() method.

->store(storage_path("app/{$path}"), 's3', \Maatwebsite\Excel\Excel::CSV);

Are you btw sure this is correct? You want s3 and the full path? Shouldn't you just pass ->store($path, 's3', 'Csv') ?

@jgodish
Copy link
Author

jgodish commented Jun 19, 2019

Sorry for the confusion on that, I think I was trying some stuff and pasted the wrong thing. I can confirm it's using the path in s3.

public function exportUnsubscribes() {
	$path = 'exports/'.app()->environment()."/test-export.csv";

	$unsubscribes = new Unsubscribes($this->start_date, $this->end_date);

	$unsubscribes->forAccount($this->account)->store($path, 's3', \Maatwebsite\Excel\Excel::CSV);
}

Then in s3 we have the exports/local/ folder where it should be stored.

I ran it again to be sure of what I listed previously. When I change put to use $source->contents() instead of $readStream it stores in s3. Otherwise, it won't work and gives the checksum error.

image

@patrickbrouwers
Copy link
Member

Ah okay the path is okay then. I'm not sure what's causing it, for me s3 is working fine with using a remote temporary file.

Perhaps it's an idea to consider our commercial support so we can prioritize looking into this for you? You can see the possibilities here: https://laravel-excel.com/commercial-support Feel free to send us an email so we can discuss it further.

@jgodish
Copy link
Author

jgodish commented Jul 5, 2019

I did a bit more digging and believe I have narrowed it down some more. I don't have enough experience with reading/writing files to suggest why this might be happening.

In the file Maatwebsite\Excel\Files\LocalTemporaryFile -> readStream method the issue seems to be related to the "b+" mode flag. If I remove the + so the mode is rb it works as expected. If I change it to r+b it also works as expected. I have read that the "b" specifies it's a binary file but I have not found anything on doing b+. I'm not sure if it's possible that changing it to r+b would be a possible solution.

@patrickbrouwers
Copy link
Member

Sorry for the late reply. There's not really any reason why the + is needed I think? Can you make a PR for it. I'll give it a test round and see if it has any impact.

@jgodish
Copy link
Author

jgodish commented Aug 10, 2019

I finally found some time to submit a PR. I looked through things and I don't believe the "+" is needed either because it should only be used for reading a file, not writing to it (I could be wrong though).

@jochemfuchs
Copy link
Contributor

jochemfuchs commented Aug 21, 2019

Hi @jgodish
I've looked at your PR, and it's not something we can use. It can break the package for other users and it doesn't actually have anything to do with your issue.

For reference r+b and rb+ mean the exact same thing. The b can be added at the end, or between the r and +. It makes no difference.

Having said that, I'm not sure why you experience different behaviour on your end, but we are unable to reproduce the same here and therefore must conclude the issue is not within the package.

Feel free to contact us for commercial support and we can take a look into your exact situation and code to try and solve the issue there. Or if you have more information that might help pinpoint this, feel free to open a new ticket with this information.

@petriuslima
Copy link

petriuslima commented Mar 26, 2020

The same error occurs to me while uploading (using method store) a xlsx to s3.

Changing the characters order solves the problem and leaves in accordance with php documentation for fopen.

PR #2605

@petriuslima
Copy link

@jochemfuchs May you check this issue again with this new PR #2605 or is better to create a new one?

@petriuslima
Copy link

@patrickbrouwers Can you help me?

@diaazaiter
Copy link

/** @var array Hash of readable and writable stream types */ private static $readWriteHash = [ 'read' => [ 'r' => true, 'w+' => true, 'r+' => true, 'x+' => true, 'c+' => true, 'rb' => true, 'w+b' => true, 'r+b' => true, 'x+b' => true, 'c+b' => true, 'rt' => true, 'w+t' => true, 'r+t' => true, 'x+t' => true, 'c+t' => true, 'a+' => true ], 'write' => [ 'w' => true, 'w+' => true, 'rw' => true, 'r+' => true, 'x+' => true, 'c+' => true, 'wb' => true, 'w+b' => true, 'r+b' => true, 'x+b' => true, 'c+b' => true, 'w+t' => true, 'r+t' => true, 'x+t' => true, 'c+t' => true, 'a' => true, 'a+' => true ] ];

the problem here is with older versions of guzzlehttp/psr7.
In vendor/guzzlehttp/psr7/src/Stream.php where it considers any stream with a mode not belonging to $readWriteHash['read'] as non-readable, and that's what happening with the 'rb+' mode. Since 'r+b' belongs to the above array it doesn't throw that checksum exception

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

6 participants