Skip to content

Commit

Permalink
better upload
Browse files Browse the repository at this point in the history
  • Loading branch information
David-Crty committed Oct 11, 2020
1 parent 5e78110 commit 6748d8a
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/UploadToS3.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ private function getClient(){
}

private function getContentDisposition(File $file){
return 'attachment; filename="'.$file->getName().'"';
$filename = mb_convert_encoding($file->getName(), "US-ASCII");
return 'attachment; filename="'.$filename.'"';
}

/**
Expand All @@ -48,12 +49,18 @@ private function getContentDisposition(File $file){
public function uploadFile(File $file, $mainFolder){
$source = fopen($file->getRealPath(), 'rb');
$key = $file->generateS3Key($mainFolder);
$before = function (\Aws\Command $command) use ($file) {
$command['ContentType'] = $file->getMineType();
$command['ContentDisposition'] = $this->getContentDisposition($file);
};

$uploader = new ObjectUploader(
$this->getClient(),
Env::get('AWS_BUCKET'),
$key,
$source
$source,
'private',
['before_upload' => $before]
);

do {
Expand All @@ -70,10 +77,7 @@ public function uploadFile(File $file, $mainFolder){
'key' => $file->generateS3Key($mainFolder),
'concurrency' => 2,
'part_size' => 100000000, // 100 Mo
'before_initiate' => function (\Aws\Command $command) use ($file) {
$command['ContentType'] = $file->getMineType();
$command['ContentDisposition'] = $this->getContentDisposition($file);
},
'before_initiate' => $before,
]);
}
} while (!isset($result));
Expand Down

0 comments on commit 6748d8a

Please sign in to comment.