diff -u b/src/Controller/S3CorsUploadAjaxController.php b/src/Controller/S3CorsUploadAjaxController.php --- b/src/Controller/S3CorsUploadAjaxController.php +++ b/src/Controller/S3CorsUploadAjaxController.php @@ -79,11 +79,8 @@ ['acl' => $post['acl']], ['bucket' => $bucket], ['starts-with', '$key', $destination . '/'], - ['Content-Disposition' => 'attachment; filename="' . $post['filename'] . '"'], ]; - $post['Content-Disposition'] = 'attachment; filename="' . $post['filename'] . '"'; - // Retrieve the file name and build the URI. // Destination does not contain a prefix as it is applied by the fly system. $uri = \Drupal::service('file_system')->createFilename($post['filename'], $post['destination']); @@ -99,6 +96,20 @@ ]); $file->save(); + // Set file mime so browser would know how to handle them eg images are + // shown not downloaded. + $file_mime = $file->getMimeType(); + $options[]['Content-Type'] = $file_mime; + $post['Content-Type'] = $file_mime; + + // For downloadable files always download with original name. + // @todo: Is 'application/*' mime enough? + if (strpos($file_mime, 'application/') === 0) { + $content_disposition = 'attachment; filename="' . $post['filename'] . '"'; + $options[]['Content-Disposition'] = $content_disposition; + $post['Content-Disposition'] = $content_disposition; + } + // Remove values not necessary for the request to Amazon. unset($post['destination']); unset($post['filename']);