Esempio n. 1
0
def AddImageByUrl(url,fileName,tag):
    result = urlfetch.fetch(url)
    if result.status_code == 200:
        name = fileName
        mtype = result.headers.get('Content-Type', '')
        bits = result.content
        gf=GaeFile()
        gf.open(name,mtype);
        gf.write(bits)
        id=gf.close()
        
        image=Images(description="/media/?key="+str(id))
        image.mime=result.headers.get('Content-Type', '')
        image.filetype=image.mime
        # if image.mime.find('image')==-1:
            # return None
        image.size=len(bits)
        image.width=-1;
        image.height=-1;
        # image.name=fileName
        # image.filetype,image.width,image.height=getImageInfo(image.bf)
        image.tag=tag.split(',')
        image.put()
        AddTags(image.tag)
        return image
    else:
        return None
Esempio n. 2
0
def AddImageByUrlBak(url,fileName,tag):
    result = urlfetch.fetch(url)
    if result.status_code == 200:
        image=Images(description=url,bf=result.content)
        image.mime=result.headers.get('Content-Type', '')
        if image.mime.find('image')==-1:
            return None
        image.size=len(image.bf)
        image.name=fileName
        image.filetype,image.width,image.height=getImageInfo(image.bf)
        image.tag=tag.split(',')
        image.put()
        AddTags(image.tag)
        return image
    else:
        return None