diff options
author | Florian Pritz <bluewind@xssn.at> | 2010-10-24 11:19:45 +0200 |
---|---|---|
committer | Florian Pritz <bluewind@xssn.at> | 2010-10-24 11:19:45 +0200 |
commit | 45cdf314e4eaa3ff7c0e48ae64b45c00a4f45964 (patch) | |
tree | 03f745b873a06a4e25ff89537542e84a8a4da18e | |
parent | f7be5d413416d558357ba2d2310f2e08800da9ac (diff) |
reduce memory consumption when uploading
Pipeing the file to curl causes curl to store it in memory until it
recieves an EOF. Therefore we should only use a pipe if we can't upload
dynamic files.
Signed-off-by: Florian Pritz <bluewind@xssn.at>
-rwxr-xr-x | fb | 14 |
1 files changed, 11 insertions, 3 deletions
@@ -58,9 +58,17 @@ do_upload() { return 1 fi fi - if ! cat "$file" | curl -# -n -L -A $USERAGENT $EXTRA -F "file=@-;filename=$basefilename" "$PASTEBIN/file/do_upload" > $TMPFILE; then - EXITCODE=1 - return 1 + CURLOPTS="-# -n -L -A $USERAGENT $EXTRA" + if [ `stat -c %s "$file"` -eq "0" ]; then + if ! curl $CURLOPTS -F "file=@-;filename=$basefilename" "$PASTEBIN/file/do_upload" < "$file" > $TMPFILE; then + EXITCODE=1 + return 1 + fi + else + if ! curl $CURLOPTS -F "file=@$file" "$PASTEBIN/file/do_upload" > $TMPFILE; then + EXITCODE=1 + return 1 + fi fi sed '$d' $TMPFILE >&2 URL=`tail -1 $TMPFILE` |