Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
Pythonista Upload Photos from Library
-
Hey Guys,
i Have a new idea and a new Question xD
is it Possible to select multiple Photos from my complete Photo-Library and upload it to my server via ftps ?
i found this on the documentation:
import photos assets = photos.pick_asset(title='Pick some assets', multi=True) print(assets)
here i can select some vids and pics.
but how i get the path of the files to use it in ftp ?
and nice to have were to rename each fileis this possible ?
-
@DavinE use, for each asset, something like
filename = str(ObjCInstance(asset).valueForKey_('filename')) pil = asset.get_image() pil.save(filename, quality=95)
Then you can send your local file and remove it after.
-
This post is deleted! -
@cvp,
this is my code:
import os, sys import photos assets = photos.pick_asset(title='Pick some assets', multi=True) print(f'assets: {assets}') for asset in assets: pil = asset.get_image(original=False) pil.show() #print(filename) filename = 'test.PNG' pil.save(os.path.join(os.path.dirname(sys.argv[0]), filename), quality=95)
this works good but is it possible to change the filename like this:
pil = asset.get_image(original=False) console.quicklook(pil) #print(filename) filename = '%s%s' % (console.input_alert('Rename File', 'Message: rename File', hide_cancel_button=False), '.PNG') pil.save(os.path.join(os.path.dirname(sys.argv[0]), filename), quality=95)
or better show the image in console.input_alert thus you know what you are renaming ?
-
@DavinE for the file name, testing your code would be the best answer 🙄
-
@DavinE console.quicklook needs a path, not a pil
filename = 'test.PNG' console.quicklook(filename)
-
@DavinE this works
pil = asset.get_image(original=False) #pil.show() #print(filename) filename = 'test.PNG' console.quicklook(filename) filename = '%s%s' % (console.input_alert('Rename File', 'Message: rename File', hide_cancel_button=False), '.PNG') pil.save(os.path.join(os.path.dirname(sys.argv[0]), filename), quality=95)
-
@cvp said:
@DavinE this works
pil = asset.get_image(original=False) #pil.show() #print(filename) filename = 'test.PNG' console.quicklook(filename) filename = '%s%s' % (console.input_alert('Rename File', 'Message: rename File', hide_cancel_button=False), '.PNG') pil.save(os.path.join(os.path.dirname(sys.argv[0]), filename), quality=95)
No this works not because
console.quicklook(filename)
did not existspil.save
is called later...
i think what i want to do this don't works.. -
-
-
@DavinE thus, all is ok?
-
@DavinE said:
No this works not because console.quicklook(filename) did not exists pil.save is called later...
i think what i want to do this don't works..You are right, sorry. But you can always rename your file after saving it as local.
If you only need to upload the file and to not keep a local copy, usealways the same temp name for local save, thus the quicklook will work.get asset
pil.save as local tempname
quicklook tempname
ask name
Upload to name
remove tempname local -
@cvp said:
@DavinE said:
No this works not because console.quicklook(filename) did not exists pil.save is called later...
i think what i want to do this don't works..You are right, sorry. But you can always rename your file after saving it as local.
If you only need to upload the file and to not keep a local copy, usealways the same temp name for local save, thus the quicklook will work.yes, i got the same idea ;)
here's the code:
assets = photos.pick_asset(title='Pick some assets', multi=True) print(f'assets: {assets}') for asset in assets: pil = asset.get_image(original=False) pil.save(os.path.join(os.path.dirname(sys.argv[0]), 'Images', filename), quality=95) for image in os.listdir(os.path.join(os.path.dirname(sys.argv[0]), 'Images')): console.quicklook((os.path.join(os.path.dirname(sys.argv[0]), 'Images', image))) filename = '%s%s' % (console.input_alert('Rename File', 'Message: rename File', hide_cancel_button=False), '.PNG') # Upload......
Thanks for your help @cvp
-
@DavinE I have edited my post just before reading your last one
-
@cvp the post above yours or which one ?
-
If you want to ftp upload the picked photos, I think you get the asset a binary data and to upload it without passing via a local copy.
Of course, if you want to show the photo without a local file, you can't use quicklook but an ImageView could be sufficient to show the image.... -
-
I don't have any FTP server accessible just now, but you can test this
#pil.save(os.path.join(os.path.dirname(sys.argv[0]), filename), quality=95) temp = io.BytesIO() pil.save(temp, format='JPEG', quality=95) temp.seek(0) #session.storbinary('STOR xxxxx.jpg' , temp)
The pil.save needs a format because, without file name, file type would be unknown
-
Please, if you try this one, please let me know if it is ok
import console import os, sys import photos import io import ui assets = photos.pick_asset(title='Pick some assets', multi=True) for asset in assets: pil = asset.get_image(original=False) iv = ui.ImageView() iv.image = asset.get_ui_image() iv.present('fullscreen') #pil.save(os.path.join(os.path.dirname(sys.argv[0]), filename), quality=95) temp = io.BytesIO() pil.save(temp, format='JPEG', quality=95) temp.seek(0) filename = '%s%s' % (console.input_alert('Rename File', 'Message: rename File', hide_cancel_button=False), '.PNG') #session.storbinary('STOR '+filename , temp)
-
@cvp said:
Please, if you try this one, please let me know if it is ok
import console import os, sys import photos import io import ui assets = photos.pick_asset(title='Pick some assets', multi=True) for asset in assets: pil = asset.get_image(original=False) iv = ui.ImageView() iv.image = asset.get_ui_image() iv.present('fullscreen') #pil.save(os.path.join(os.path.dirname(sys.argv[0]), filename), quality=95) temp = io.BytesIO() pil.save(temp, format='JPEG', quality=95) temp.seek(0) filename = '%s%s' % (console.input_alert('Rename File', 'Message: rename File', hide_cancel_button=False), '.PNG') #session.storbinary('STOR '+filename , temp)
this looks nice.
i try it.