[contentbox] Adding a PDF link to a page

Dan,

If you are getting that error message, then it is failing a file exists. The way it works is it checks for the existence of the file, if it is not found then it throws that error. If you follow the media manager model, it uses the default media provider and tries to deliver the file based on the location in the media settings.

I have seen some issues where if the extension is upper case, it needs to be renamed to be lower case and I am not sure why. I haven’t had the time to investigate the cause of that…

Basically it takes the setting and does an expandPath on that setting to get the location of the file, as you are getting that error it means the expanding of the path and the file name is seen as non existent.

Not sure what more I can add here, but unless there is something in the coldbox logs that indicates something else then I am not sure I can advise anything else.

Are you using IIS or Apache? I’ve seen IIS return 404s if it didn’t have a MIME type registered.

Can you put an abort in Application.cfc to confirm if the request is even hitting CF. Can you show your rewrite config? Since you’re not using the index.cfm in your URL, it will be up to your rewrite engine to recognize the __media bit and rewrite it as index.cfm/__media. If it’s just seeing the .png and passing it through as a static image for IIS/Apache to process, then CF will never even get the request.

Thanks!

~Brad

ColdBox Platform Evangelist
Ortus Solutions, Corp

E-mail: brad@coldbox.org
ColdBox Platform: http://www.coldbox.org
Blog: http://www.codersrevolution.com

Brad, this is not an IIS error.

The error is

404: Requested path not found

This is thrown by the Media handler, as you can see below

// Check if media path detected
if( !len( prc.mediaPath ) OR !mediaProvider.mediaExists( prc.mediaPath ) ){
// return invalid media
return invalidMedia(event,rc,prc);
}

And invalidMedia is

// Invalid Media
private function invalidMedia(event,rc,prc){
// Announce invalid media
var iData = { mediaPath = prc.mediaPath };
announceInterception( “cbui_onInvalidMediaRequest”, iData );
// Render invalid media
event.renderData(data=“

404: Requested path not found

”, statusCode=“404”, statusText=“Requested Path Not Found”);
}

So you were able to reproduce Dan’s error locally? Does it happen on all URLs or just some? What URL are you using and how is it getting past your rewrites to CF?

Thanks!

~Brad

ColdBox Platform Evangelist
Ortus Solutions, Corp

E-mail: brad@coldbox.org
ColdBox Platform: http://www.coldbox.org
Blog: http://www.codersrevolution.com

Yes.

If you read my replies it is all in there…

Sorry, there were dozens of E-mails from this weekend and I tried to skim them all this morning.

I saw this line:
RewriteCond %{REQUEST_URI} .(bmp|gif|jpe?g|png|css|js|txt|xls|ico|swf)$

but didn’t notice this line too:
RewriteCond %{REQUEST_URI} /__media/

Thanks!

~Brad

ColdBox Platform Evangelist
Ortus Solutions, Corp

E-mail: brad@coldbox.org
ColdBox Platform: http://www.coldbox.org
Blog: http://www.codersrevolution.com

Yeah Dan said they are there.

The only thing that I have noticed is with the file name and cases. For example this on my PC

testJpgImage.JPG when uploaded via Media Manager, shows up as a broken image when I try to insert it into any content. Even browsing the URL /__media/testJpgImage.JPG will throw an error, the same error Dan is getting.

When I change the url too

/__media/testJpgImage.jpg

The image will be displayed. The strange thing is that I haven’t noticed anything that cold be causing this, and not that I have really looked either.

Now this may or may not be the same issue Dan is having, which is why I mentioned this to Dan and am waiting to see what Dan has discovered now.

Andrew,
No there isn’t much to this file. In fact its nothing private so I am adding it to this message. Can you give it a try and see if it works for you?

DonationRequestLetter_2013.pdf (39.5 KB)

I am using Apache.

What do you mean by putting an abort it? I have a whole site up and running locally, this is actually 1 of 2 small issues I need to fix up before I can launch it. Here is what my rewrite rules and routes look like

RewriteEngine on
#RepeatLimit 0

#SQL Injection Protection --Read More www.cybercrime.gov
#Please uncomment to use these rules if below words does not conflict with your friendly-urls. You may modify accordingly.
#RewriteRule ^.EXEC(@.$ /includes/templates/404.html [L,F,NC]
#RewriteRule ^.CAST(.$ /includes/templates/404.html [L,F,NC]
#RewriteRule ^.DECLARE.$ /includes/templates/404.html [L,F,NC]
#RewriteRule ^.DECLARE%20.$ /includes/templates/404.html [L,F,NC]
#RewriteRule ^.NVARCHAR.$ /includes/templates/404.html [L,F,NC]
#RewriteRule ^.sp_password.$ /includes/templates/404.html [L,F,NC]
#RewriteRule ^.%20xp_.$ /includes/templates/404.html [L,F,NC]

BLOCK unsupported HTTP methods

#RewriteCond %{REQUEST_METHOD} !^(GET|HEAD|OPTIONS|POST|PROPFIND|TRACE)$
#RewriteRule .* - [F]

#You may also want to block proxy attempts, if you see those in your logs:

BLOCK attempts to use our server as a proxy, but allow absolute URIs (change example.com to your domain)

#RewriteCond %{THE_REQUEST} ^(GET|HEAD|POST)./?http:// [NC]
#RewriteCond %{THE_REQUEST} !^(GET|HEAD|POST)./?http://(www.)?example.com/
#RewriteRule .* - [F]

#if this call related to adminstrators or non rewrite folders, you can add more here.
RewriteCond %{REQUEST_URI} ^/(.(CFIDE|cfide|CFFormGateway|jrunscripts|railo-context|mapping-tag|fckeditor)).$
RewriteRule ^(.*)$ - [NC,L]

#dealing with flash / flex communication
RewriteCond %{REQUEST_URI} ^/(.(flashservices|flex2gateway|flex-remoting)).$
RewriteRule ^(.*)$ - [NC,L]

#font awesome
AddType application/vnd.ms-fontobject .eot
AddType font/ttf .ttf
AddType font/otf .otf
<FilesMatch “.(ttf|otf|eot|woff)$”>

Header set Access-Control-Allow-Origin “*”

Media Types

RewriteCond %{REQUEST_URI} /__media/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.cfm/%{REQUEST_URI} [QSA,L,NS]

#Images, css, javascript and docs, add your own extensions if needed.
RewriteCond %{REQUEST_URI} .(bmp|gif|jpe?g|png|css|js|txt|xls|ico|swf)$
RewriteRule ^(.*)$ - [NC,L]

#The ColdBox index.cfm/{path_info} rules.
RewriteRule ^$ index.cfm [QSA,NS]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.cfm/%{REQUEST_URI} [QSA,L,NS]

// Allow unique URL or combination of URLs, we recommend both enabled setUniqueURLS(false); // Auto reload configuration, true in dev makes sense to reload the routes on every request //setAutoReload(false); // Sets automatic route extension detection and places the extension in the rc.format variable // setExtensionDetection(true); // The valid extensions this interceptor will detect setValidExtensions('xml,json,jsont,rss,html,htm,cfm,print,pdf,doc'); // If enabled, the interceptor will throw a 406 exception that an invalid format was detected or just ignore it // setThrowOnInvalidExtension(true);

// Base URL
if( len(getSetting(‘AppMapping’) ) lte 1){
setBaseURL(“http://#cgi.HTTP_HOST#/index.cfm”);
}
else{
setBaseURL(“http://#cgi.HTTP_HOST#/#getSetting(‘AppMapping’)#/index.cfm”);
}

// Add Module Routing Here
addModuleRoutes(pattern="/forgebox",module=“forgebox”);

// Your Application Routes
addRoute(pattern=":handler/:action?");

Dan,

Got the same issue here, funny thing is if you rename it to jpg it will work.

haha really? I am setup to allow pdf though, really odd. Wonder what’s going on. Is this all pdf’s or just my pdf?

Dan,

You’re not going crazy, I did some more investigation and there is a definite bug here. For some reason, ContentBox is stripping the pdf extension, so when it tries to validate the files existence, it is checking minus the extension so it will fail.

Luis, might know exactly what the issue is, but I can;t see the issue at the moment.

Pretty odd… im guessing the same thing is happening with .png files then too. I can use jpg just fine but using png is having the same result as the pdf.

Yeah, I know what the issue is and maybe how to fix it. If you give me a few minutes to test something, I will post back here.

The solution will require a custom module, but I can step you through that till a fix is provided.

But to give you an idea on the problem, I will have to take a step back to what ColdBox is all about.

When requesting information from the server, one can do something like this.

/register/privacy/

And you will get a view to view the privacy documentation in a normal view, however with little changes we could do this.

/register/privacy,pdf

And now ColdBox knows to know run that handler with the intent to display it as a PDF. ContentBox has the issue, that when the media handler runs to to provide the image, ColdBox has already done its magic and hence it thinks it is now an actual handler when it is not.

Anyway, give me a minute and I will provide a quick and dirty solution.

Ok Dan, here is your temporary fix.

You do not need to understand this, and will be happy to explain it later if you need. But the first thing you need to do is create a module for ContentBox. You can place this in the ContentBox modules, however I would prefer to place this in the ColdBox modules folder as it can’t get be accidentally removed via the dashboard.

Once you have created a module, which you can do with the CFBuilder ColdBox tools. Then remove everything that you are not going to use, you can leave all the defaults if you like.

Now we will create a folder in the root of this module, which we will name AOP. Then create a file in here called MediaService.cfc and add the following code to it.

component implements=“coldbox.system.aop.MethodInterceptor” {

property name=“log” inject=“logbox:logger:{this}”;

//------------------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------------------
public any function init(required boolean logResults=“true”) {
instance = {
logResults = arguments.logResults
};
return this;
}

//------------------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------------------
public any function invokeMethod(required invocation) {
var refLocal = {};

var args = invocation.getArgs();
var event = args.event;
var rc = event.getCollection();
var prc = event.getCollection(private = true);

if(prc.currentRoutedUrl.endsWith("/")) {
prc.currentRoutedUrl = left(prc.currentRoutedUrl, len(prc.currentRoutedUrl) - 1) & “.” & rc.format;
}

refLocal.results = arguments.invocation.proceed();

if( structKeyExists(refLocal,“results”) ){
return refLocal.results;
}
}

}

Once you have done that, then you need to open up the module config and add the following to it.

binder.mapAspect(“cronusCBHotFix”).to("#moduleMapping#.aop.mediaService");

// bind the aspect
binder.bindAspect(classes=binder.match().instanceOf(“contentbox-ui.handlers.media”),
methods=binder.match().methods(“index”),
aspects=“cronusCBHotFix”);

Once you have done this, you can then use the Dashboard to reload the application. And your pdf should now work. If you delve into the code, it is very self explanatory, but feel free to ask away.

ok one more change, as it does error on images now. So replace the MediaService.cfc with the following for the invoke method.

//------------------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------------------
public any function invokeMethod(required invocation) {
var refLocal = {};

var args = invocation.getArgs();
var event = args.event;
var rc = event.getCollection();
var prc = event.getCollection(private = true);

if(prc.currentRoutedUrl.endsWith("/") && structKeyExists(rc, “format”)) {
prc.currentRoutedUrl = left(prc.currentRoutedUrl, len(prc.currentRoutedUrl) - 1) & “.” & rc.format;
}

refLocal.results = arguments.invocation.proceed();

if( structKeyExists(refLocal,“results”) ){
return refLocal.results;
}
}

The purpose of the abort was to determine if the 404 status code is being returned by Apache or by CF. If it’s coming from Apache, your abort would never be reached. If it’s coming from CF, the abort would fire before ContentBox had a chance to process the request.

Thanks!

~Brad

ColdBox Platform Evangelist
Ortus Solutions, Corp

E-mail: brad@coldbox.org
ColdBox Platform: http://www.coldbox.org
Blog: http://www.codersrevolution.com

Andrew, can you tell us what we need to change in ContentBox to avoid this issue for good?

Thanks!

~Brad

ColdBox Platform Evangelist
Ortus Solutions, Corp

E-mail: brad@coldbox.org
ColdBox Platform: http://www.coldbox.org
Blog: http://www.codersrevolution.com

Brad, damn almost typed Bard again… :stuck_out_tongue:

Anyway, the conditional statement in the AOP should be enough to add to the media handlers index method. but I would maybe look at what extensions should be allowed, for example txt, json etc would not be viable options for media content.

What do others suggest?

Have you put in a ticket yet. If not, I’ll put one in.

What if the automatic detection of extensions was simply skipped for the __media route? I would hate to place any limits on the type of files someone might want to server from there.

Thanks!

~Brad

ColdBox Platform Evangelist
Ortus Solutions, Corp

E-mail: brad@coldbox.org
ColdBox Platform: http://www.coldbox.org
Blog: http://www.codersrevolution.com