How can I stop sorl thumbnail from breaking with very long filenames?
Posted
by bitbutter
on Stack Overflow
See other posts from Stack Overflow
or by bitbutter
Published on 2010-05-14T15:39:00Z
Indexed on
2010/05/14
15:44 UTC
Read the original article
Hit count: 381
I've noticed that when working with SORL thumbnail, sometimes a user will upload an image with a very long filename, longer than the varfield in the database can hold. The name gets truncated in the database and the project gives errors whenever the image is requested.
Is there a smart and safe way to have django automatically truncate long filenames in sorl uploads (prior to saving them in the database) to prevent this sort of thing?
As reference, here's how the relevant model from my current project looks:
class ArtistImage(models.Model):
artist = models.ForeignKey(Artist)
position = models.IntegerField()
image = ThumbnailField(
thumbnail_tag='<span class="artistimagewrapper"><img class="artistimage" src="%(src)s" width="%(width)s" height="%(height)s"></span>',
upload_to='uploaded_images/artistimages',
size=(900,900),
quality=100,
options={'crop': 'center'},
extra_thumbnails={
'small':{
'size':(92,92),
'quality':100,
'options':{'crop': 'center'},
}
}
)
class Meta:
ordering = ('image',)
def __unicode__(self):
return (u"%s" % self.image)
© Stack Overflow or respective owner