upload
upload copied to clipboard
Something went wrong when I tried to upload a image to AWS S3
Bug Report
Something went wrong when I tried to upload a image to AWS S3 ,I can see the image in my Bucket, whitch mean it had been successfully uploaded . But that image cannot be inserted into the edit box automatically, it can only be added manually using the media manager.
Environment
- Flarum version: 1.4.1
- Extension version:1.2.3
- Website URL: https://www.dtcommunity.top/
- Webserver: [nginx]
- Hosting environment: [vps]
- PHP version: 8.0.20
- Browser: [chrome]
I turned on debug mode and saw some error messages
POST https://www.dtcommunity.top/api/fof/upload
<br />
<b>Warning</b>: is_readable(): open_basedir restriction in effect. File(/home/www/.aws/config) is not within the allowed path(s): (/www/wwwroot/community.dtnetwork.top/:/tmp/) in <b>/www/wwwroot/community.dtnetwork.top/vendor/aws/aws-sdk-php/src/DefaultsMode/ConfigurationProvider.php</b> on line <b>152</b><br />
<br />
<b>Fatal error</b>: Uncaught Laminas\HttpHandlerRunner\Exception\EmitterException: Output has been emitted previously; cannot emit response in /www/wwwroot/community.dtnetwork.top/vendor/laminas/laminas-httphandlerrunner/src/Exception/EmitterException.php:24
Stack trace:
#0 /www/wwwroot/community.dtnetwork.top/vendor/laminas/laminas-httphandlerrunner/src/Emitter/SapiEmitterTrait.php(40): Laminas\HttpHandlerRunner\Exception\EmitterException::forOutputSent()
#1 /www/wwwroot/community.dtnetwork.top/vendor/laminas/laminas-httphandlerrunner/src/Emitter/SapiEmitter.php(27): Laminas\HttpHandlerRunner\Emitter\SapiEmitter->assertNoPreviousOutput()
#2 /www/wwwroot/community.dtnetwork.top/vendor/laminas/laminas-httphandlerrunner/src/RequestHandlerRunner.php(98): Laminas\HttpHandlerRunner\Emitter\SapiEmitter->emit()
#3 /www/wwwroot/community.dtnetwork.top/vendor/flarum/core/src/Http/Server.php(44): Laminas\HttpHandlerRunner\RequestHandlerRunner->run()
#4 /www/wwwroot/community.dtnetwork.top/public/index.php(26): Flarum\Http\Server->listen()
#5 {main}
thrown in <b>/www/wwwroot/community.dtnetwork.top/vendor/laminas/laminas-httphandlerrunner/src/Exception/EmitterException.php</b> on line <b>24</b><br />
Tried turning off anti-cross-site attacks when I saw "open_basedir", and the functionality returned to normal, but it's probably not a good solution .
I'm not sure, but from the error message and location I would guess the Amazon SDK automatically tries to find some configuration files in common locations.
I'm not sure if we can explicitly tell the SDK to not do that :thinking:
I'm not sure either. I wouldn't expect a config file on a production server.
This would need some investigation.
嘿! 你们有什么进展吗?有解决方法了吗?
@LiteCat0905 @essesoul can you provide more details on how you configured the S3 adapter with FoF Upload?
From the error message my guess is that the OP left the credentials empty, which causes the AWS SDK to lookup default credentials on the server, however PHP basedir restrictions prevent the SDK from reading files out of the Flarum folder.
In that case the next question is: where are you trying to read credentials from? If you provided credentials directly in the Flarum extension settings, then that's an error for us to fix. Can you provide steps to reproduce from a fresh VPS? If you are really trying to let the SDK use global credentials, then you need to fix your PHP configuration to allow the SDK to read the /home/www/.aws
folder.
I'm also not sure whether /home/www/.aws
is really a default location or if it's being read from an environment variable. In that case you might also need to adjust the variable if you are trying to read global configuration from elsewhere.
I really don't know enough about the AWS PHP SDK to know in which order and where global configuration is read. The idea is that if you put credentials in the Flarum extension, we forward it to the SDK and it shouldn't look elsewhere. But maybe it still looks for other configuration files in a global folder. If the SDK has a method to call to prevent looking for files out of the Flarum folder we could add a new option for that in the extension settings, but I don't know if that's a thing. We'll need some help with people familiar with the AWS SDK.
This issue has been automatically closed because it received no activity for three months. If you think it was closed by accident, please leave a comment. If you are running into a similar issue on the latest version, please open a new issue. Thank you.