Glennmen's avatar

Wrong file extension after AWS S3 upload

I am trying to upload APK files to AWS S3 Bucket but they are being saved as ZIP files. Laravel 5.6, PHP 7.1.16

This code worked before, but I wanted to change it because the issue of overwriting existing files:

$path = $apkFile->storeAs('update-server', $apkFile->getClientOriginalName(), ['disk' => 's3', 'visibility' => 'public']);

I tried this to upload it with a random filename but it saves the file as ZIP:

$path = Storage::disk('s3')->putFile('update-server', $apkFile, ['mimetype' => 'application/vnd.android.package-archive', 'visibility' => 'public']);

I added mimetype after I found this example: https://github.com/laravel/framework/pull/16416#issuecomment-263599069 but it doesn't seem to work in this case.

I need the S3 storage path to be able to save it in my DB.

Any info in the right direction would help me a lot!

0 likes
1 reply
Glennmen's avatar
Glennmen
OP
Best Answer
Level 1

The current solution I found is generating a random name myself and not letting it use $this->guessExtension()that is used in putFile().

Current solution:

$path = Storage::disk('s3')->putFileAs('update-server', $apkFile, Str::random(40), ['mimetype' => 'application/vnd.android.package-archive', 'visibility' => 'public']);

Any suggestions/improvements are still welcome.

Please or to participate in this conversation.