The file property in the front matter of markdown files published by ocw-studio locally are relative paths pointing to the file from the root of any given host
Current Behavior
The file property is prefixed with the value of AWS_STORAGE_BUCKET_NAME, i.e. /ol-ocw-studio-app/courses/ocw-ci-test-course/example_pdf.pdf
Steps to Reproduce
Import or create a course in ocw-studio using the local Docker setup
Publish said course
Browse to the Github repo for the course and find a resource
Possible Solution
When using the setting OCW_STUDIO_USE_S3=true, the django-storages backend automatically generates the url property of FileFields using the configured AWS settings. In local development, AWS settings are overridden to use a locally running instance of Minio. An automatically generated URL to a resource in AWS proper looks something like: 'https://ol-ocw-studio-app-qa.s3.amazonaws.com/courses/6-450-principles-of-digital-communications-i-fall-2006/c59828b4e470fd50daf31f0f7251456c_quiz1_04_soln.pdf'. Locally, you will see URLs like 'http://10.1.0.100:9000/ol-ocw-studio-app/courses/ocw-ci-test-course/example_pdf.pdf'. This happens because endpoint_url is overridden to hit Minio, and a different URL strategy is used.
In the full_metadata property of the WebsiteContent model, the file URL is set using full_metadata[file_field["name"]] = urlparse(file_url).path. If you look at the above URLs, you will see why the bucket name is being included locally. Since the bucket name is part of the path and not the domain, it gets included when you call the path property of the parsed URL. The bucket name should be filtered out of the path if it is being included.
Expected Behavior
The
file
property in the front matter of markdown files published byocw-studio
locally are relative paths pointing to the file from the root of any given hostCurrent Behavior
The
file
property is prefixed with the value ofAWS_STORAGE_BUCKET_NAME
, i.e./ol-ocw-studio-app/courses/ocw-ci-test-course/example_pdf.pdf
Steps to Reproduce
ocw-studio
using the local Docker setupPossible Solution
When using the setting
OCW_STUDIO_USE_S3=true
, thedjango-storages
backend automatically generates theurl
property ofFileField
s using the configured AWS settings. In local development, AWS settings are overridden to use a locally running instance of Minio. An automatically generated URL to a resource in AWS proper looks something like:'https://ol-ocw-studio-app-qa.s3.amazonaws.com/courses/6-450-principles-of-digital-communications-i-fall-2006/c59828b4e470fd50daf31f0f7251456c_quiz1_04_soln.pdf'
. Locally, you will see URLs like'http://10.1.0.100:9000/ol-ocw-studio-app/courses/ocw-ci-test-course/example_pdf.pdf'
. This happens becauseendpoint_url
is overridden to hit Minio, and a different URL strategy is used.In the
full_metadata
property of theWebsiteContent
model, the file URL is set usingfull_metadata[file_field["name"]] = urlparse(file_url).path
. If you look at the above URLs, you will see why the bucket name is being included locally. Since the bucket name is part of the path and not the domain, it gets included when you call thepath
property of the parsed URL. The bucket name should be filtered out of the path if it is being included.