• sebietter

    I'm using paramiko to (successfully) connect to my server using SFTP. I tried to upload an image chosen via photos.pick_image() but can't get Pythonista to upload the image.

    My code:

    import paramiko
    import photos
    from io import BytesIO
    import urllib
    import datetime
    # SFTP Configuration
    host = 'MyHost'
    port = 22
    transport = paramiko.Transport((host, port))
    password = 'MyPassword"
    username = 'MyUsername'
    transport.connect(username = username, password = password)
    sftp = paramiko.SFTPClient.from_transport(transport)
    # Image & Link Setup
    today = datetime.datetime.now()
    image = photos.pick_image()
    print image
    fileName = 'ios'
    fileName = fileName + '_' + today.strftime("%Y-%m-%d-%H%M%S") + '.png'
    urlBase = 'myURL'
    encodedFileName = urllib.quote(fileName)
    print fileName
    remoteFilePath = 'MyPath'
    # Upload the image
    sftp.put(image, remoteFilePath + fileName)
    print 'Upload done!'
    # Paste image link to clipboard
    clipboard.set(urlBase + encodedFileName)

    I'd be really grateful if one of you could explain me what I'm doing wrong and how I could solve my problem of not being able to upload an image.

    posted in Pythonista read more
  • sebietter

    I don't know if anybody is even interested but as a little follow up I'd like to quickly explain how I was able to solve the problem. I simply saved the image to my Pythonista library and uploaded it from there:

    imgSaved = image.save(fileName)

    And then upload it using the sftp.put command:

    sftp.put(fileName, remoteFilePath + fileName)

    With os.remove(fileName) the file can finally be removed from the Pythonista library to keep everything clean.

    posted in Pythonista read more
Internal error.

Oops! Looks like something went wrong!