def addChefAPICalls(newChef,request,username): api = BasicClient('VATx6OASrU4KYLaWshrxIvyyYUIl8x','xkpKJ3Wti1cXilKJYnMSqaOLvmNnwe') #make folder for pictures pictureFolder = '/ChefPicture/'+str(newChef.id)+'/' api.post('/path/oper/mkdir',path=pictureFolder) p = request.FILES['chef_picture'] picName = p.name.split(".") tempPictureName = "tmp."+picName[-1] with open(tempPictureName, 'wb+') as destination: for chunk in p.chunks(): destination.write(chunk) destination.close() #im = Image.open(StringIO(file(tempPictureName,"rb").read())) im = Image.open(tempPictureName) size = 64, 64 im.save(picName[0]+"."+picName[-1], "JPEG", quality=30) im.thumbnail(size, Image.ANTIALIAS) im.save("thumb.jpg", "JPEG") #upload picture fileName = username+'_'+picName[0]+'.'+picName[-1] api.post('/path/data'+pictureFolder, file=(fileName, open(picName[0]+"."+picName[-1], 'r').read())) api.post('/path/data'+pictureFolder, file=(picName[0]+'_thumb.jpg', open('thumb.jpg', 'r').read())) rpic = ChefPicture.objects.create(chef=newChef) rpic.setPath(fileName, pictureFolder) rpic.setSmallPath(picName[0]+'_thumb.jpg', pictureFolder) os.system("rm "+tempPictureName)
def addRecipeAPICalls(ids,request,recipe,recipeName): api = BasicClient('VATx6OASrU4KYLaWshrxIvyyYUIl8x','xkpKJ3Wti1cXilKJYnMSqaOLvmNnwe') #make folder for pictures pictureFolder = '/RecipePicture/'+ids+'/' api.post('/path/oper/mkdir',path=pictureFolder) firstLoop = True for p in request.FILES.getlist('picture'): picName = p.name.split(".") tempPictureName = "tmp."+picName[-1] with open(tempPictureName, 'wb+') as destination: for chunk in p.chunks(): destination.write(chunk) destination.close() #im = Image.open(StringIO(file(tempPictureName,"rb").read())) im = Image.open(tempPictureName) size = 64, 64 im.save(picName[0]+"."+picName[-1], "JPEG", quality=30) im.thumbnail(size, Image.ANTIALIAS) im.save("thumb.jpg", "JPEG") #upload picture fileName = recipeName+'_'+picName[0]+'.'+picName[-1] api.post('/path/data'+pictureFolder, file=(fileName, open(picName[0]+"."+picName[-1], 'r').read())) api.post('/path/data'+pictureFolder, file=(picName[0]+'_thumb.jpg', open('thumb.jpg', 'r').read())) #make picture object rpic = recipe.recipepicture_set.create() rpic.setPath(fileName,pictureFolder) rpic.setSmallPath(picName[0]+'_thumb.jpg',pictureFolder) if firstLoop: #set this pic as recipe's main pic recipe.mainPicture = rpic recipe.save() firstLoop = False os.system("rm "+tempPictureName)
def upload_smartfile(request): file_path = request.GET.get('filepath') #path api = BasicClient("TxHYvbTZHmxnYcpTWvFYXKwPVb1xUh","Qlw9pGFhtl0MJFiOkBBWDLco4bV0yX") file = open(file_path,'rb') api.upload(os.path.split(file_path)[1],file) return HttpResponse("<h1>UPLOADED</h1>")
def smartFile(self): self.smartFileClient = BasicClient(os.getenv('smartfile_api_key'), os.getenv('smartfile_api_password'))
def getClient(self, **kwargs): kwargs.setdefault('key', API_KEY) kwargs.setdefault('password', API_PASSWORD) kwargs.setdefault('url', 'http://127.0.0.1:%s/' % self.server.server_port) return BasicClient(**kwargs)
def setUp(self): self.api = BasicClient(API_KEY, API_PASSWORD) # Make directory for tests self.api.post('/path/oper/mkdir/', path=TESTFN2)
class CustomOperationsTestCase(unittest.TestCase): def setUp(self): self.api = BasicClient(API_KEY, API_PASSWORD) # Make directory for tests self.api.post('/path/oper/mkdir/', path=TESTFN2) def get_data(self): data = self.api.get("/path/info/testfn") return data def tearDown(self): self.api.remove('/testfn2') os.remove('testfn') def upload(self): f = StringIO(file_contents) f.seek(0) self.api.upload(TESTFN, f) self.assertEquals(self.get_data()['size'], f.len) def download(self): self.api.download(TESTFN) self.assertEquals(self.get_data()['size'], os.path.getsize(TESTFN)) def move(self): self.api.move(TESTFN, TESTFN2) def remove(self): self.api.remove(os.path.join(TESTFN2, TESTFN)) with self.assertRaises(ResponseError): self.api.remove(os.path.join(TESTFN2, TESTFN)) def test_upload_download_move_delete(self): self.upload() self.download() self.move() self.remove()
class CustomOperationsTestCase(unittest.TestCase): def setUp(self): self.api = BasicClient(API_KEY, API_PASSWORD) # Make directory for tests self.api.post('/path/oper/mkdir/', path=TESTFN2) def get_data(self): data = self.api.get("/path/info/testfn") return data def tearDown(self): self.api.remove('/testfn2') os.remove('testfn') def upload(self): f = StringIO(file_contents) f.seek(0) self.api.upload(TESTFN, f) self.assertEquals(self.get_data()['size'], f.tell()) def download(self): response = self.api.download(TESTFN, False) self.assertTrue(isinstance(response, requests.Response)) self.api.download(TESTFN) self.assertEquals(self.get_data()['size'], os.path.getsize(TESTFN)) def move(self): self.api.move(TESTFN, TESTFN2) def remove(self): self.api.remove(os.path.join(TESTFN2, TESTFN)) with self.assertRaises(ResponseError): self.api.remove(os.path.join(TESTFN2, TESTFN)) def test_upload_download_move_delete(self): self.upload() self.download() self.move() self.remove()
from smartfile import BasicClient api = BasicClient("TxHYvbTZHmxnYcpTWvFYXKwPVb1xUh", "Qlw9pGFhtl0MJFiOkBBWDLco4bV0yX") #with open("img.jpg",'rb') as file: # api.upload('picture',file)
def setPath(self, fileName, pictureFolder): api = BasicClient('VATx6OASrU4KYLaWshrxIvyyYUIl8x','xkpKJ3Wti1cXilKJYnMSqaOLvmNnwe') #creating link to picture response = api.post('/link',path=pictureFolder+fileName,read=True) self.path = response['href']+fileName self.save()
from smartfile import BasicClient import zlib api = BasicClient('VATx6OASrU4KYLaWshrxIvyyYUIl8x','xkpKJ3Wti1cXilKJYnMSqaOLvmNnwe') f = api.get('/path/data/', 'TemplateEmailTable.txt') decompString = zlib.decompress(f.data, 16+zlib.MAX_WBITS) print decompString