@patrick I have a question about your Server Action for S3 Download file.
I’m converting my website from PHP to NodeJS and I’m not getting the Download Progress Bar to work with Node and S3 Download file.
Is it possible that there is something missing in the code for NodeJS to work with the Progress Bar? In PHP it does work without problems.
After looking at your code I found out, that there are “obviously” a lot of differences between the code for Node and PHP:
PHP:
public function downloadFile($options) {
option_require($options, 'provider');
option_require($options, 'bucket');
option_require($options, 'key');
$options = $this->app->parseObject($options);
$s3 = $this->getClient($options->provider);
if (!$s3->doesObjectExist($options->bucket, $options->key)) {
$this->app->response->end(404);
}
$result = $s3->getObject([
'Bucket' => $options->bucket,
'Key' => $options->key
]);
header('Content-Type: ' . $result['ContentType']);
header('Content-Disposition: attachment; filename="' . basename($options->key) . '"');
header('Content-Length: ' . $result['ContentLength']);
exit($result['Body']);
}
Node:
downloadFile: async function(options) {
const provider = this.parseRequired(options.provider, 'string', 's3.downloadFile: profider is required.');
const Bucket = this.parseRequired(options.bucket, 'string', 's3.downloadFile: bucket is required.');
const Key = this.parseRequired(options.key, 'string', 's3.downloadFile: key is required.');
const s3 = this.getS3Provider(provider);
if (!s3) throw new Error(`S3 provider "${provider}" doesn't exist.`);
this.res.attachment(basename(Key));
s3.getObject({ Bucket, Key }).createReadStream().pipe(this.res);
this.noOutput = true;
}