edwardspec / mediawiki-aws-s3

Extension:AWS allows MediaWiki to use Amazon S3 (instead of the local directory) to store images.
https://www.mediawiki.org/wiki/Extension:AWS
GNU General Public License v2.0
42 stars 32 forks source link

Retrieving a thumbnail via standard MediaWiki browsing results in error "Sorry, the file cannot be displayed", while file is successfully uploaded #21

Closed doctorpangloss closed 5 years ago

doctorpangloss commented 5 years ago

Possibly related to #11 .

Steps to reproduce:

  1. Visit this wiki page.
  2. Click the image.
  3. Observe "Sorry, the file cannot be displayed."
  4. Observe that the image URL in the error message is indeed navigable.

Uploading works.

Adding the following CORS policy to the bucket fixes the problem:

<CORSConfiguration>
 <CORSRule>
   <AllowedOrigin>*</AllowedOrigin>
   <AllowedMethod>GET</AllowedMethod>
 </CORSRule>
</CORSConfiguration>
edwardspec commented 5 years ago

Your wiki has Extension:MultimediaViewer, which tries to download the thumbnail via JavaScript. This fails due to CORS restrictions (cross-origin requests): browser won't allow JavaScript from domain A to send requests to domain B, unless B allows it.

(here A is your wiki's domain and B is domain of Amazon S3)

Solution is to allow these requests in "CORS configuration" of your S3 bucket with images. See https://docs.aws.amazon.com/AmazonS3/latest/user-guide/add-cors-configuration.html for details.

edwardspec commented 5 years ago

Something like this will probably work:

<CORSConfiguration>
 <CORSRule>
   <AllowedOrigin>https://wiki.hiddenswitch.com/</AllowedOrigin>
   <AllowedMethod>GET</AllowedMethod>
   <AllowedHeader>*</AllowedHeader>
   <MaxAgeSeconds>3000</MaxAgeSeconds>
 </CORSRule>
</CORSConfiguration>
doctorpangloss commented 5 years ago

I went ahead and documented that fix.