From 45cdf314e4eaa3ff7c0e48ae64b45c00a4f45964 Mon Sep 17 00:00:00 2001 From: Florian Pritz Date: Sun, 24 Oct 2010 11:19:45 +0200 Subject: 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 --- fb | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/fb b/fb index 30c02f7..5df2370 100755 --- a/fb +++ b/fb @@ -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` -- cgit v1.2.3-24-g4f1b