I successfully added Fastly as a CDN for serving static content but theres one problem after enabling the CDN module:

File upload is not possible anylonger.

The following error occurs on file upload:
InvalidArgumentException: The URI '//example.com/sites/default/files/2016-04/Scan.jpeg' is invalid. You must use a valid URI scheme. in Drupal\Core\Url::fromUri() (line 306 of /home/r0ea6/www/core/lib/Drupal/Core/Url.php).

Steps to reproduce :

  • enable cdn, active it and set up any domain for testing, in this case (example.com) no js / css will be loaded but thats okay
  • create an article and upload a file, on upload click the upper error is shown.

Proposed resolution:
Only alter the file base path on view not on upload.

CommentFileSizeAuthor
#13 interdiff.txt353 byteswim leers
#13 2711529-12.patch725 byteswim leers
#12 2711529-11.patch404 byteswim leers

Comments

yobottehg created an issue. See original summary.

wim leers’s picture

Priority: Major » Critical

This is due to a documented core bug. From the alpha1 release notes:

  1. #1783278: Scheme-relative URL rejected by validation: (core issue) to allow the CDN module to work in tandem with file upload widgets, which currently cause errors due to this core bug

But it's probably good to track it in the CDN module issue queue as well, so thanks for that

wim leers’s picture

yobottehg’s picture

Component: Module » Origin Pull mode

just to be extra safe, this will probably solve the error, but the file upload still goes to the wrong url i think.
I my use case i serve all static assets via a fastly domain but uploads should still be done using the default domain.

So from my point of view CDN should not alter the domain while uploading a file.

yobottehg’s picture

okay i was wrong.

The patch fixes the problem.

wim leers’s picture

Yes. Everything in #4 is speculation, which as it turns out, is wrong :) If it were correct, then I'd agree with you that that would be bad!

wim leers’s picture

Title: File Upload not possible with active CDN » [PP-1] File Upload not possible with active CDN
Status: Active » Postponed
wim leers’s picture

wim leers’s picture

wim leers’s picture

Title: [PP-1] File Upload not possible with active CDN » File upload widget broken when using CDN module, fixed in Drupal 8.1.3: require that version
Component: Origin Pull mode » Code
Assigned: Unassigned » wim leers
Status: Postponed » Active

Yay, #2573635: Url::fromUri() should accept protocol-relative URLs landed, which means that once Drupal 8.1.3 is released and people start using that version, this problem will be a thing of the past!

wim leers’s picture

wim leers’s picture

Status: Active » Needs review
StatusFileSize
new404 bytes
wim leers’s picture

StatusFileSize
new725 bytes
new353 bytes

Also updated composer.json per https://getcomposer.org/doc/articles/versions.md.

webflo’s picture

Status: Needs review » Reviewed & tested by the community

Patch #12 is good to go. A dedicated composer.json is not necessary for internal (drupal modules and themes) dependencies.

wim leers’s picture

Thanks for your confirmation, @webflo!

I'll remove the CDN module's composer.json.

  • Wim Leers committed 011f63a on 8.x-3.x
    Issue #2711529 by Wim Leers, webflo: File upload widget broken when...
wim leers’s picture

Status: Reviewed & tested by the community » Fixed
wim leers’s picture

Title: File upload widget broken when using CDN module, fixed in Drupal 8.1.3: require that version » File upload widget broken when using CDN module, fixed in Drupal 8.1.4: require that version
Status: Fixed » Postponed

8.1.3 was released yesterday, but it doesn't include this. Because it's a security release that doesn't contain anything except for the security fixes.

So, I was a bit too quick. It's probably going to be 8.1.4, but let's not make the same mistake again. Postponing this issue on the 8.1.4 release that will likely include this fix.

wim leers’s picture

Status: Postponed » Active

And now this fix has indeed made it into the 8.1.4 release: https://www.drupal.org/project/drupal/releases/8.1.4.

  • Wim Leers committed 0e62e93 on 8.x-3.x
    Issue #2711529 follow-up by Wim Leers, webflo: File upload widget broken...
wim leers’s picture

Status: Active » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.