Multiple upload controls on a docType... can I get file sizes?
I just realized that the upload datatype doesn't store
umbracoBytes, which means I have no way of getting and displaying the size of the uploaded file. All I have is the url to the file.
I could add a label (aka, static text) property to my docType called 'umbracoBytes' and it would be auto-populated (and this is VERY cool!) but... I've got four upload fields and whatever item is uploaded last will put its filesize in the 'umbracoBytes' field. I need to know the size of each of the uploads.
I don't want to resort to forcing the users to upload the four files to the media section by hand (even
with zip upload), and then have to go back to the content area and select each of those files with a media picker. The files aren't re-used so the simplicity of uploading directly from the docType is fantastic. I just need to get the filesize from each of the upload fields.
Or, if you'd like to avoid the calls in xslt, register for save events on documents, check doc type and set a read-only property (label) with filesize of upload -> bit of a hack, but all work is done in backend and can be retrieved in xslt quite fast.
If you don't like to show the bytes field on the doc type, think @ismayat has done some work on hiding properties from a user (think it was done in jquery talk)
Maybe your event handler just checks if there are any properties of type Upload and then appends "_umbracoBytes" and updates the properties accordingly.
Therefore if your upload control was called 'ImageFile' the event handler would set 'ImageFile_umbracoBytes' to the filesize property.
This should then make the solution quite flexible.
I think it's better to do this check once and cache the values than check the filesize every page load.
Thanks, guys! I was pulling my hair out on this one and you all presented the voice of sanity and good advice when I needed. Thanks!
I'm marking Thomas' answer as the solution because it is the one I used on the site. It was quick and easy to implement, right inside my xslt macro. Performance is very good and I'll be caching this macro heavily as well.
If performance does ever become an issue I'll create an event handler to write the upload size for each control as Dirk and Chris suggested, as that will maximize performance.
Here's the relevant bits of the xslt macro for reference:
Multiple upload controls on a docType... can I get file sizes?
I just realized that the upload datatype doesn't store umbracoBytes, which means I have no way of getting and displaying the size of the uploaded file. All I have is the url to the file.
I could add a label (aka, static text) property to my docType called 'umbracoBytes' and it would be auto-populated (and this is VERY cool!) but... I've got four upload fields and whatever item is uploaded last will put its filesize in the 'umbracoBytes' field. I need to know the size of each of the uploads.
I don't want to resort to forcing the users to upload the four files to the media section by hand (even with zip upload), and then have to go back to the content area and select each of those files with a media picker. The files aren't re-used so the simplicity of uploading directly from the docType is fantastic. I just need to get the filesize from each of the upload fields.
Any ideas?
Write an xslt extension getting the bytes:
Thomas
Or, if you'd like to avoid the calls in xslt, register for save events on documents, check doc type and set a read-only property (label) with filesize of upload -> bit of a hack, but all work is done in backend and can be retrieved in xslt quite fast.
If you don't like to show the bytes field on the doc type, think @ismayat has done some work on hiding properties from a user (think it was done in jquery talk)
Might be quite some overhead tho...
Cheers,
/Dirk
Thinking about Dirks suggestion....
Maybe your event handler just checks if there are any properties of type Upload and then appends "_umbracoBytes" and updates the properties accordingly.
Therefore if your upload control was called 'ImageFile' the event handler would set 'ImageFile_umbracoBytes' to the filesize property.
This should then make the solution quite flexible.
I think it's better to do this check once and cache the values than check the filesize every page load.
Thanks, guys! I was pulling my hair out on this one and you all presented the voice of sanity and good advice when I needed. Thanks!
I'm marking Thomas' answer as the solution because it is the one I used on the site. It was quick and easy to implement, right inside my xslt macro. Performance is very good and I'll be caching this macro heavily as well.
If performance does ever become an issue I'll create an event handler to write the upload size for each control as Dirk and Chris suggested, as that will maximize performance.
Here's the relevant bits of the xslt macro for reference:
cheers,
doug.
I agree that I would like to see the file upload data type store the extra details inside the single data element, rather than across several others.
IE, use xml to save all the properties, various thumbs, etc.
Thought, Doug, I like your approach! :P
You may want to use my multiple file uploader
Download it here. http://our.umbraco.org/projects/backoffice-extensions/multiple-file-uploader
Thanks
is working on a reply...