# coding: utf-8 # Pythonisitaからサーバアクセスするコード例 import requests import random import photos import console from objc_util import * def take_photo(filename='.temp.jpg'): img = photos.capture_image() if img: img.save(filename) return filename else: print("failed.") def pick_photo(filename='.temp.jpg'): img = photos.pick_image() if img: img.save(filename) return filename else: print("failed.") def main(): console.clear() i = console.alert('Info', 'Chose input device.\n\n', 'Take a new photo','Pick an image from camera roll') if i == 1: filename = take_photo() else: filename = pick_photo() if not filename: return chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789' sendname="".join([random.choice(chars) for x in range(64)]) img = open(filename, 'rb') url = "http://www.hirax.net:8080/upload" responce = requests.post(url, files = { "name": ("", sendname, "text/plain; charset=UTF-8"), "upload": ("src.jpg", img, "image/jpeg") }) file = open(".tmp.jpg", "wb") file.write(responce.content) file.close() console.show_image(".tmp.jpg") print('Tap and hold the image to save it to your camera roll.') if __name__ == '__main__': main()