Best method to transfer data to PC
HT last edited by
I've got an app in which the user draws multiple images in succession. The images are stored in an array. I'm wondering what the best method would be to transfer that data to a computer.
Unfortunately I can't get the dropbox synchronator to work. An alternative I tried is to send a mail with the data. But I don't know how to attach the images or how to create a text file with the pixel Matrix that I could attach.
cvp last edited by
@HT If your PC is WiFi connected to your iDevice, and if the PC runs a (S)FTP server (standard in Windows or Mac OS), you could send it via (S)FTP, what is quicker than attach an image to an email, send it, receive the mail, detach...
mikael last edited by
Here’s something you can start from. This one is meant to be placed in the wrench menu, either sending the file being edited or the whole directory to the SFTP server, then executing the code and returning the output, i.e. a fast-feedback development environment for a headless server.
For your purposes, you could save the images to a directory, then send them all to a server.
#coding: utf-8 import paramiko import editor, console import os.path import sys console.clear() local_path = editor.get_path() remote_path = os.path.basename(local_path) local_dir_path = os.path.dirname(local_path) remote_dir_path = local_dir_path.split('/')[-1] server_address = "184.108.40.206" server_port = 22 username = "username" password = "password" print('Open SSH connection') s = paramiko.SSHClient() s.set_missing_host_key_policy(paramiko.AutoAddPolicy()) s.connect(server_address, server_port, username=username, password=password, timeout=4) sftp = s.open_sftp() fixed_local_root = None fixed_remote_root = 'magicmirror' try: sftp.mkdir(fixed_remote_root) except: pass # Ok if already exists if sys.argv == 'dir': print('--- Send directory') #sftp.put(local_dir_path, remote_dir_path) #parent = os.path.split(local_dir_path) prefix_len = len(local_dir_path) for walker in os.walk(local_dir_path): remote_sftp_path = remote_dir_path + walker[prefix_len:] if remote_sftp_path.endswith('/'): remote_sftp_path = remote_sftp_path[:-1] try: pass #sftp.mkdir(os.path.join(remotepath, walker)) except: pass for file in walker: print('put', os.path.join(walker,file), remote_sftp_path + '/' + file) #sftp.put(os.path.join(walker,file),os.path.join(remotepath,walker,file)) else: print('--- Send file') sftp.put(local_path, remote_path) if sys.argv == 'run': print('--- Run it') stdin, stdout, stderr = s.exec_command('python3 ' + remote_path) for line in stdout.readlines(): print(line.rstrip('\n')) s.close() print('--- Done') for line in stderr.readlines(): print('ERROR:', line.rstrip('\n')) print('--- Complete')
HT last edited by HT
Unfortunately I don't have access to a sftp server. I've got this part of the code, which sends me a mail. I just can't get it to attach the image to the mail:
image = photos.save_image(img) to = 'receiver' subject = 'data' gmail_pwd = 'password' gmail_user = 'sender' attachment = self.table print('Connecting...') smtpserver = smtplib.SMTP("smtp.gmail.com", 587) console.show_activity() smtpserver.ehlo() smtpserver.starttls()
smtpserver.ehlo smtpserver.login(gmail_user, gmail_pwd) # print('Preparing message...') outer = MIMEMultipart() outer['Subject'] = subject outer['To'] = to outer['From'] = gmail_user outer.preamble = 'You will not see this in a MIME-aware email reader.\n' attachment = get_attachment(image) outer.attach(attachment) composed = outer.as_string() print('Sending...') smtpserver.sendmail(gmail_user, to, composed) smtpserver.close() console.hide_activity() print('Done.')
It prints out "Get_attachment is not defined"
cvp last edited by cvp
@HT I use this code
# coding: utf-8 import smtplib # for sending an email # email package needed modules from email.mime.image import MIMEImage from email.mime.multipart import MIMEMultipart import photos from PIL import Image def main(): # Create the container email message. me = 'your email' msg = MIMEMultipart() msg['Subject'] = 'this is the subject' msg['From'] = me msg['To'] = me msg.preamble = 'Send me a photo' sel_photo = photos.pick_asset(assets=photos.get_assets(media_type='photo'),multi=False) photo = sel_photo.get_image_data().getvalue() img = MIMEImage(photo) msg.attach(img) # Send the email via our own SMTP server. s = smtplib.SMTP('your smtp server') s.sendmail(me, me, msg.as_string()) s.quit() # check if the script is running instead of be imported if __name__ == '__main__': main()
scofficial last edited by scofficial
There are many other ways to send data to your pc, the one I particularly prefer is uploading the data to a drive and downloading it on the required device. You may also try FTP server. However, the easiest method would be to use different applications that send songs, images to devices using wifi like ShareIt. You could also use the inbuilt bluetooth in your devices, if it is available. Try transferring https://sc-downloader.net/ songs with above mentioned ways to know which one is best suited for your device.