Permalink
Browse files

Fixes #3 (filenames with spaces) and use positional arguments in stri…

…ng format() for Python 2.6
  • Loading branch information...
1 parent 4cfc17b commit 308e19c0ee6af49222cd7ddad4b6a9f410882622 @dideler dideler committed Oct 5, 2012
Showing with 8 additions and 11 deletions.
  1. +8 −11 geturl
View
19 geturl
@@ -36,34 +36,31 @@ if not APIKEY:
while not email:
email = raw_input('Enter your email to link or create your filepicker.io acccount: ')
- # pretty sure this isn't public. found it by looking at the jotform integration
- APIKEY = check_output(['curl', '--silent', "%(fpurl)s/getKey?email=%(email)s" % {'fpurl': FPAPIURL, 'email': email}])
+ # Beware, others can have access to your filepicker.io space (for now).
+ APIKEY = check_output(['curl', '--silent', '{0}/getKey?email={1}'.format(FPAPIURL, email)])
if not config.has_section('filepicker'):
config.add_section('filepicker')
config.set('filepicker', 'apikey', APIKEY)
config.write(open(CONFIG_FILE, 'w+'))
# Show usage if incorrect number of args or not a file.
+if len(sys.argv) != 2:
+ print 'usage: geturl <filename>'
+ exit()
filename = sys.argv[1]
try:
f = open(filename, 'r')
- if len(sys.argv) != 2 or type(f) != file: # hasattr(f, 'read') is more Pythonic
- print 'usage: geturl <filename>'
- exit()
except IOError:
print 'usage: geturl <filename>'
+ exit()
# Upload the file.
print '\nUploading file to Filepicker.io...'
-#safe_filename = urllib.pathname2url(filename)
-safe_filename = urllib.quote_plus(filename)
+fileurl = urllib.pathname2url(filename)
curl_command = ('curl --progress-bar -F "fileUpload=@{0}" -F "apikey={1}" '
- '{2}/api/path/storage/{0}').format(filename, APIKEY, FPURL)
+ '{2}/api/path/storage/{3}').format(filename, APIKEY, FPURL, fileurl)
output = check_output(curl_command, shell=True)
-#output = check_output('curl --progress-bar -F "fileUpload=@%(filename)s" -F "apikey=%(apikey)s" %(fpurl)s/api/path/storage/%(filename)s' % {"filename": filename, "apikey": APIKEY, "fpurl": FPURL}, shell=True)
-# curl --progress-bar -F "fileUpload=@foo bar - hello_world.txt" -F "apikey=A8yuJ4aohTym_BH_TB07Lz" https://www.filepicker.io/api/path/storage/foo bar - hello_world.txt
-# output = {"data": [{"url": "https://www.filepicker.io/api/file/GGsGQM4BRHW-cKVkK4vr", "data": {"size": 0, "type": "text/plain", "filename": "test.txt"}}], "result": "ok"}
data = json.loads(output)
url = data['data'][0]['url']

0 comments on commit 308e19c

Please sign in to comment.