Skip to content

Instantly share code, notes, and snippets.

@KittyKatt
Last active Mar 24, 2018
Embed
What would you like to do?
pomf.se BASH script to upload images
#!/usr/bin/env bash
# pomf.se uploader
# requires: curl
dest_url='http://pomf.se/upload.php'
return_url='http://a.pomf.se'
if [[ -n "${1}" ]]; then
file="${1}"
if [ -f "${file}" ]; then
printf "Uploading ${file}..."
my_output=$(curl --silent -sf -F files[]="@${file}" "${dest_url}")
n=0 # Multipe tries
while [[ $n -le 3 ]]; do
printf "try #${n}..."
if [[ "${my_output}" =~ '"success":true,' ]]; then
return_file=$(echo "$my_output" | grep -Eo '"url":"[A-Za-z0-9]+.png",' | sed 's/"url":"//;s/",//')
printf 'done.\n'
break
else
printf 'failed.\n'
((n = n +1))
fi
done
if [[ -n ${return_file} ]]; then
printf "File can be found at: ${return_url}/${return_file}.\n"
else
printf 'Error! File not uploaded.\n'
fi
else
printf 'Error! File does not exist!\n'
exit 1
fi
else
printf 'Error! You must supply a filename to upload!\n'
exit 1
fi
@Zanthas

This comment has been minimized.

Copy link

@Zanthas Zanthas commented Jun 19, 2013

Awesome.

@alusion

This comment has been minimized.

Copy link

@alusion alusion commented Aug 11, 2013

<3

@KittyKatt

This comment has been minimized.

Copy link
Owner Author

@KittyKatt KittyKatt commented Nov 8, 2013

Fixed.

@Bweeze

This comment has been minimized.

Copy link

@Bweeze Bweeze commented Nov 13, 2013

KittyKatt is my favourite dev ever :3

@somini

This comment has been minimized.

Copy link

@somini somini commented Mar 11, 2015

I fixed it to add more image extension, it uploads correctly but doesn't detect the URL is the file is a jpg.
https://gist.github.com/somini/bd5f56e8e10da6b4033f

@DanielFGray

This comment has been minimized.

Copy link

@DanielFGray DanielFGray commented Mar 18, 2015

I forked it to auto detect file extension, and color-code error messages that print to stderr
https://gist.github.com/DanielFGray/2b469c8e58ab65b1a0e0

@Bandie

This comment has been minimized.

Copy link

@Bandie Bandie commented May 19, 2015

Forked because no matter what file extension. .* as regex is enough.
https://gist.github.com/Bandie/50b34d68e3fbb23e9097

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment