omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    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

    Pythonista
    2
    62
    14928
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • DavinE
      DavinE last edited by

      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 file

      is this possible ?

      cvp 1 Reply Last reply Reply Quote 0
      • cvp
        cvp @DavinE last edited by cvp

        @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.

        1 Reply Last reply Reply Quote 1
        • DavinE
          DavinE last edited by

          This post is deleted!
          1 Reply Last reply Reply Quote 0
          • DavinE
            DavinE last edited by

            @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 ?

            cvp 3 Replies Last reply Reply Quote 0
            • cvp
              cvp @DavinE last edited by

              @DavinE for the file name, testing your code would be the best answer 🙄

              DavinE 1 Reply Last reply Reply Quote 0
              • cvp
                cvp @DavinE last edited by cvp

                @DavinE console.quicklook needs a path, not a pil

                    filename = 'test.PNG'
                    console.quicklook(filename)
                
                DavinE 1 Reply Last reply Reply Quote 0
                • cvp
                  cvp @DavinE last edited by

                  @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)
                  
                  DavinE 1 Reply Last reply Reply Quote 0
                  • DavinE
                    DavinE @cvp last edited by

                    @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 exists pil.save is called later...
                    i think what i want to do this don't works..

                    cvp 1 Reply Last reply Reply Quote 0
                    • DavinE
                      DavinE @cvp last edited by

                      @cvp said:

                      @DavinE console.quicklook needs a path, not a pil

                          filename = 'test.PNG'
                          console.quicklook(filename)
                      

                      i Know i get an error xD

                      1 Reply Last reply Reply Quote 0
                      • DavinE
                        DavinE @cvp last edited by

                        @cvp said:

                        @DavinE for the file name, testing your code would be the best answer 🙄

                        i removed the Question ^^ i'm too fast

                        cvp 1 Reply Last reply Reply Quote 0
                        • cvp
                          cvp @DavinE last edited by

                          @DavinE thus, all is ok?

                          1 Reply Last reply Reply Quote 0
                          • cvp
                            cvp @DavinE last edited by cvp

                            @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

                            DavinE 1 Reply Last reply Reply Quote 0
                            • DavinE
                              DavinE @cvp last edited by

                              @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

                              cvp 1 Reply Last reply Reply Quote 0
                              • cvp
                                cvp @DavinE last edited by

                                @DavinE I have edited my post just before reading your last one

                                1 Reply Last reply Reply Quote 0
                                • DavinE
                                  DavinE last edited by

                                  @cvp the post above yours or which one ?

                                  cvp 1 Reply Last reply Reply Quote 0
                                  • cvp
                                    cvp last edited by

                                    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....

                                    1 Reply Last reply Reply Quote 0
                                    • cvp
                                      cvp @DavinE last edited by

                                      @DavinE said:

                                      the post above yours or which one ?

                                      Forget it because you found a solution

                                      1 Reply Last reply Reply Quote 0
                                      • cvp
                                        cvp last edited by cvp

                                        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

                                        1 Reply Last reply Reply Quote 0
                                        • cvp
                                          cvp last edited by cvp

                                          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)
                                          
                                          DavinE 2 Replies Last reply Reply Quote 1
                                          • DavinE
                                            DavinE @cvp last edited by

                                            @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.

                                            1 Reply Last reply Reply Quote 0
                                            • First post
                                              Last post
                                            Powered by NodeBB Forums | Contributors