Editorial Workflows

FTP Image

public workflow

Install Workflow...

This workflow contains at least one Python script. Only use it if you trust the person who shared this with you, and if you know exactly what it does.

I understand, install the workflow!

This is a workflow for Editorial, a Markdown and plain text editor for iOS. To download it, you need to view this page on a device that has the app installed.

Description: Upload image on clipboard to website folder via FTP and return MD image link into document. (Update - strips unicode characters)

Shared by: @mygeekdaddy

Comments: Comment Feed (RSS)

There are no comments yet.

+ Add Comment

Workflow Preview
Get Current File Name ?
Include Folder
Include Extension
Set Variable ?
Variable Name
Run Python Script ?
Source Code
# Python script to upload image from clipboard to ftp via Editorial WF
import workflow
import keychain
import pickle
import Image, ImageOps, ImageFilter
import ftplib
import console
import clipboard
import datetime
from io import BytesIO
import urllib

today = datetime.datetime.now()
image = clipboard.get_image()

#Pulls document title from variable in previous WF step
imgtitle = workflow.get_variable('DocTitleVar')

# Double .replace used to make image name just alphanumeric and underscores
imgtitle = imgtitle.replace (" ", "_")
imgtitle = imgtitle.replace("-_","")
# imgtitle = imgtitle.decode('utf-8')
imgtitle = imgtitle.encode('ascii', 'ignore')

imgname = '_img_'+ imgtitle + '_' + today.strftime("%Y_%m_%d_%H%M%S") +'.png'

# Uncomment this line to reset stored password
#keychain.delete_password('macdrifter', 'editorial')
login = keychain.get_password('mygeekdaddy', 'editorial')
if login is not None:
	username, passwd = pickle.loads(login)
	username, passwd = console.login_alert('FTPS Login Needed', 'No login credentials found.')
	pickle_token = pickle.dumps((username, passwd))
	keychain.set_password('mygeekdaddy', 'editorial', pickle_token)

# Change host/port/etc to values for your website
host = "verly.me"
port = 21
baseURL = "http://share.mygeekdaddy.net/"

# folder on ftp site where image will be saved
imgfolder = "/share/"

# Routine used to resize image
def customSize(img):
    w, h = img.size
    print 'w: ' + str(w)
    print 'h: '+ str(h)
# Adjust number in next line to image width.
# Currently set to 500 pixels
    if w > 500:
        wsize = 500/float(w)
        print 'wsize: '+str(wsize)
        hsize = int(float(h)*float(wsize))
        print 'hsize: ' + str(hsize)

        img = img.resize((500, hsize), Image.ANTIALIAS)
    return img

image = customSize(image)

buffer = BytesIO()
image.save(buffer, 'PNG')

imgURL = urllib.quote(imgname)

# FTP upload routine
	ftp = ftplib.FTP(host, username, passwd)	
	ftp.storbinary('STOR '+ imgname, buffer)
except Exception, e:
	print e
	console.alert('Error', e)

imageLink = baseURL + imgURL

print image.size
print imgname
print imageLink
print ''
print 'FTP upload complete.'

Replace Selected Text ?
Replacement Text