Try our conversational search powered by Generative AI!

Direct download link to MediaData type file

Dan
Dan
Vote:
 

I do have a pdf file of MediaData type. When I try to access it via it's VirtualPath, redirected to "login/CMS/edit/PreviewContainerPage.aspx" page it says "Preview is not available for this page"

So, is there any way to get direct link to this pdf file ?

#87305
Jun 10, 2014 12:30
Vote:
 

Like Johan says here:
http://world.episerver.com/Modules/Forum/Pages/Thread.aspx?id=78865&epslanguage=en

"You could use UrlResolver (resides in EPiServer.Web namespace), you can either get an instance from IOC container or use static property Current. 

UrlResolver have several overloaded methods GetUrl that returns links. The most basic one takes a single ContentReference and returns the url in the same format as the current context is executing (so if the code executes on site the url will be public while if the code is executign e.g. in onpageedit mode the url will be in edit format.)"

#87306
Jun 10, 2014 12:53
Vote:
 

That indicates you don't have enough access rights for the file. Is it published?

Frederik

#87307
Jun 10, 2014 13:29
Dan
Vote:
 

Thanks Henrik & Frederik for your reply

Henrik,

Yes, i'm using

UrlResolver.Current.GetUrl(myMediafile.ContentLink)

to get the file path. But when try to access the pdf file using path return by the UrlResolver i'm getting above "Preview is not available for this page" thing. So, i just wanted to know how can fix this

Frederik,

It has read access to everyone. What do you mean by "Is it published?". I have drag and drop this pdf file in to a media folder in the EpiServer site. didn't do any sort of publish initially. (do publish only if I have change some content setting of the file in the edit mode)

#87325
Jun 10, 2014 15:29
Vote:
 

Hi,

Please try an extension method in EPiServer.Cms.Shell.dll (EPiServer.Cms.Shell.IContentExtensions) like this:

var mediaContent = _contentRepository.Get<IContent>(contentLink);
var directDownloadUrl = mediaContent.DownloadUrl();

//Ha Bui

#87343
Jun 11, 2014 6:32
Dan
Vote:
 

Thanks Habu for your reply

I have used the "DownloadUrl()". But still redirected to "login/CMS/edit/PreviewContainerPage.aspx" page having "Preview is not available for this page" text

Did I missing something here ?

#87345
Jun 11, 2014 8:14
Dan
Vote:
 

It's strange that when we deployed same code in to staging server, things working perfectly (able to download/view pdf file). But this is not working in local dev environment

So, actually

UrlResolver.Current.GetUrl(myMediafile.ContentLink)


 working fine in the staging environment and able to access the file. But in the local dev environment always getting "Preview is not available for this page"

Confused a lot with this matter and haven't have any idea about this behaviour

#87375
Jun 11, 2014 20:13
Dan
Vote:
 

Finally found the root cause. In the dev environment "MVC Template" setting of "Display Template" in "DocumentMedia" (where pdf falls) Media Type is set to "DefaultMediaPreviewController". Just clearing out that value (letting it blank) resolve the issue.

#87377
Edited, Jun 11, 2014 21:07
Vote:
 

Great that you found out the solution and good to have it here if there are anyone else that will see the same error

#87386
Jun 12, 2014 7:52
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.