How to limit file size on commit?

This pre-commit hook will do the file size check: .git/hooks/pre-commit #!/bin/sh hard_limit=$(git config hooks.filesizehardlimit) soft_limit=$(git config hooks.filesizesoftlimit) : ${hard_limit:=10000000} : ${soft_limit:=500000} list_new_or_modified_files() { git diff –staged –name-status|sed -e ‘/^D/ d; /^D/! s/.\s\+//’ } unmunge() { local result=”${1#\”}” result=”${result%\”}” env echo -e “$result” } check_file_size() { n=0 while read -r munged_filename do f=”$(unmunge “$munged_filename”)” h=$(git ls-files … Read more

Finding file’s size

Try this; NSDictionary *fileAttributes = [[NSFileManager defaultManager] attributesOfItemAtPath:URL error:&attributesError]; NSNumber *fileSizeNumber = [fileAttributes objectForKey:NSFileSize]; long long fileSize = [fileSizeNumber longLongValue]; Note that the fileSize won’t necessarily fit in an integer (especially a signed one) although you could certainly drop to a long for iOS as you’ll never exceed that in reality. The example uses long … Read more

Ajax – Get size of file before downloading

You can get XHR response header data manually: http://www.w3.org/TR/XMLHttpRequest/#the-getresponseheader()-method This function will get the filesize of the requested URL: function get_filesize(url, callback) { var xhr = new XMLHttpRequest(); xhr.open(“HEAD”, url, true); // Notice “HEAD” instead of “GET”, // to get only the header xhr.onreadystatechange = function() { if (this.readyState == this.DONE) { callback(parseInt(xhr.getResponseHeader(“Content-Length”))); } }; … Read more

File-size format provider

I use this one, I get it from the web public class FileSizeFormatProvider : IFormatProvider, ICustomFormatter { public object GetFormat(Type formatType) { if (formatType == typeof(ICustomFormatter)) return this; return null; } private const string fileSizeFormat = “fs”; private const Decimal OneKiloByte = 1024M; private const Decimal OneMegaByte = OneKiloByte * 1024M; private const Decimal OneGigaByte … Read more

s3 direct upload restricting file size and type

If you are talking about security problem (people uploading huge file to your bucket), yes, You CAN restrict file size with browser-based upload to S3. Here is an example of the “policy” variable, where “content-length-range” is the key point. “expiration”: “‘.date(‘Y-m-d\TG:i:s\Z’, time()+10).'”, “conditions”: [ {“bucket”: “xxx”}, {“acl”: “public-read”}, [“starts-with”,”xxx”,””], {“success_action_redirect”: “xxx”}, [“starts-with”, “$Content-Type”, “image/jpeg”], [“content-length-range”, … Read more

Find size of Git repository

Note that, since git 1.8.3 (April, 22d 2013): “git count-objects” learned “–human-readable” aka “-H” option to show various large numbers in Ki/Mi/GiB scaled as necessary. That could be combined with the -v option mentioned by Jack Morrison in his answer. git gc git count-objects -vH (git gc is important, as mentioned by A-B-B‘s answer) Plus … Read more