How to stop clients from uploading PDF files in type="image"

  • I haven't tried this out but you could try adding the 'file-type' attribute found on 'type="file" field types? long shot but it might work. So you'd have something like:


    Code
    1. <perch:content id="img" type="image" label="Picture" help="Don't use PDF!!!" file-type="img" crop width="100" height="100" />


    You could settle for using 'file' field type and forgo the resizing/cropping and use some frontend markup/css to crop and resize. Not ideal I know but at least it would limit the 'PDF damage'...

  • The file-type attribute filters existing assets in the asset chooser. I think the editor can still upload PDF files.


    It's not ideal that Perch allows selecting PDFs in an image field. One option could be to add a conditional to not render the PDF files at all so the user is forced to pick an image instead:


    HTML
    1. <perch:if id="image" match="!contains" value=".pdf">
    2. <img src="<perch:content id="image" type="image" label="Image">" alt="">
    3. </perch:if>


    The above doesn't really cover all cases because it will also match any file path of an image that contains .pdf like /perch/resources/my.pdf_elephant.jpg.