By hooking into the RoutedContent event, I can see that the correct route is being hit and the correct content is fetched - still no clue to what causes the 404.
However, I turned on a bit more logging and I found this in the logs:
2019-02-01 12:13:52,534  ERROR EPiServer.Global: Unhandled exception in ASP.NET
System.Web.HttpException (0x80004005): Not Found.
at EPiServer.Web.BlobHttpHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result)
at System.Web.HttpApplication.ExecuteStepImpl(IExecutionStep step)
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
Maybe this means there is something going on with reading the blob from the content (though I can do that just fine in the RoutedContent-eventhandler).
My next step is implementing a custom http handler to see if I can replicate the log error, but if anyone knows what this could be, all help is appreciated.
I made a custom httphandler for the media type and replaced Episerver's BlobHttpHandler with my own implemenation (using identical reflected code) and as it turns out the problem was that the content was failing Episervers publish-check - IsPendingPublish was set to true (even though Published was also true and StartPublish was two days ago, this caused it to fail the check).
Setting IsPendingPublish to false upon creating the Content in the ContentProvider resolved the issue.
We've made a custom ContentProvider for listing a document structure from Sharepoint.
Since the structure is outside the asset root, according to some examples you can add routes for it like we're doing in an IInitializableModule:
This works fine in Edit-mode, we can download the documents from there, but in View-mode we get 404.
The URL we're trying to access (as it appears by for instance dragging a file into a XHTML-property looks like this: /sharepoint/rovvilt/sno-rovviltkontakter/rovviltkontakter.xlsx which is correct according to the document structure.
Any hints would be appreaciated!