My end goal is to use Pythonista to upload video taken on my iPhone to Vimeo by way of their API. Using their official library (installed via StaSH), uploads are easy: Just provide a path to a local file. Generally, I'd like to select a video from Photo Roll, write it to Pythonista's local storage, upload it to Vimeo, then remove it from local storage. I'm writing the file, and it has the correct length in bytes, but the upload fails (it creates a tombstone at Vimeo, a zero-length file), and the file in local storage doesn't play when I try opening it in an external resource (Quick Look -> Save in Dropbox; won't play on phone or desktop). Here's what I have so far (truncating a few bits related to patching metadata into the uploaded file, plus local storage file removal):
# coding: utf-8
import vimeo
import photos
from io import BytesIO
from objc_util import ObjCInstance
client = vimeo.VimeoClient(token='my_api_token')
video_asset = photos.pick_asset()
video_data = video_asset.get_image_data()
video_bytes = video_data.getvalue()
filename = str(ObjCInstance(video_asset).filename())
with open(filename, 'wb') as video:
video.write(video_bytes)
video.close()
video_uri = client.upload(filename)
I feel like I'm missing something obvious here, but I can't figure out what it is. Any help is much obliged. :)