Created
October 7, 2012 23:31
-
-
Save dlion/3849963 to your computer and use it in GitHub Desktop.
bash function to upload on my filepicker.io space my file from CLI.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# upfile | |
# Copyright (C) 2012 Domenico Luciani aka DLion | |
# This program is free software: you can redistribute it and/or modify | |
# it under the terms of the GNU General Public License as published by | |
# the Free Software Foundation, either version 3 of the License, or | |
# (at your option) any later version. | |
# This program is distributed in the hope that it will be useful, | |
# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
# GNU General Public License for more details. | |
# You should have received a copy of the GNU General Public License | |
# along with this program. If not, see <http://www.gnu.org/licenses/>. | |
function upfile() | |
{ | |
#Function for upload my file online in my space | |
#Site url | |
URL="https://www.filepicker.io" | |
#If you don't have any apikey you have to go on this link: https://developers.filepicker.io/getKey?email=YOUR@EMAIL.HERE and insert it into an APIKEY variable | |
#API key | |
APIKEY="INSERT HERE YOUR API KEY" | |
if [ "$1" != "" ]; then | |
#Take every single word of name of file | |
for i in $1; do | |
if [[ ! "$UP" ]]; then | |
local UP="$i" | |
else | |
UP="$UP $i" | |
fi | |
done | |
#Change space blank in %20 -> "Hello World" | "Hello%20World" | |
URLFILE=$(echo "$UP" | sed 's/ /%20/g') | |
DATA=$(curl --progress-bar -F "fileUpload=@$UP" -F "apikey=$APIKEY" "$URL/api/path/storage/$URLFILE" | grep -Po '"url":.*?[^\\]",' | grep -Po '"https://.*?"' | sed -e 's/"//g') | |
if [[ "$2" == "-s" ]]; then | |
DATA="$DATA?dl=false" | |
fi | |
echo -e "\nFile : $UP\nUrl: $DATA\n" | |
else | |
echo "usage: upfile <file> [-s show file]" | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment