Пример #1
0
def save_photo(binary):
    from tools import save_file

    mime, ext = get_img_type(binary)
    if mime == ImageMime.UNKNOWN:
        raise Exception("unsupported image format")

    filename = str(uuid.uuid1()) + ext
    url, real_file = save_file(binary, filename, mime_type=mime)

    url_thumb = real_file_thumb = ""
    try:
        import StringIO
        from PIL import Image
        from settings import THUMB_SIZE

        im = Image.open(StringIO.StringIO(binary))
        thumb = StringIO.StringIO()
        thumb_filename = str(uuid.uuid1()) + "_thumb" + ext
        im.thumbnail(THUMB_SIZE)
        thumb.name = thumb_filename
        im.save(thumb)
        url_thumb, real_file_thumb = save_file(thumb.getvalue(), thumb_filename, mime_type=mime)
    except:
        logging.exception("save thumb error")

    return url, real_file, url_thumb, real_file_thumb, mime
Пример #2
0
def save_data_for_uploaded(uploaded_filenames, uploaded_file_contents):
    """Save uploaded files"""
    if ((uploaded_filenames is not None)
            and (uploaded_file_contents is not None)
            and ('.csv' in uploaded_filenames[0])):
        for name, data in zip(uploaded_filenames, uploaded_file_contents):
            save_file(name, data)
    def download(self):
        """
        When calling - uses func "getDir" for matching working directory
        searching matched sounds and downloads their with same name
        """

        path = self.getDir()

        for i, elem in enumerate(self.check_colbox()):

            if elem:
                filename = self.ui.tableWidget.item(i, 1).text()
                ts.save_file(filename, path, self.my_req, i)
Пример #4
0
def save_photo(binary):
    mime, ext = get_img_type(binary)
    if mime == ImageMime.UNKNOWN:
        raise Exception("unsupported image format")

    rand_str = str(uuid.uuid1())
    filename = rand_str + ext

    if QINIU_SETTINGS.Enabled:
        url, url_thumb = save_file_qiniu(binary, filename, mime)

        return url, url, url_thumb, url_thumb, mime

    else:
        from tools import save_file

        url, real_file = save_file(binary, filename, mime_type=mime)

        url_thumb = real_file_thumb = ""
        try:
            import StringIO

            from PIL import Image
            from settings import THUMB_SIZE

            im = Image.open(StringIO.StringIO(binary))
            im.thumbnail(THUMB_SIZE, Image.ANTIALIAS)

            thumb = StringIO.StringIO()
            thumb.name = filename
            im.save(thumb)
            binary = thumb.getvalue()
            thumb.close()

            mime, ext = get_img_type(binary)
            thumb_filename = rand_str + "_thumb" + ext

            url_thumb, real_file_thumb = save_file(binary,
                                                   thumb_filename,
                                                   mime_type=mime)
        except:
            logging.exception("save thumb error")

        return url, real_file, url_thumb, real_file_thumb, mime
Пример #5
0
def save_photo(binary):
    mime, ext = get_img_type(binary)
    if mime == ImageMime.UNKNOWN:
        raise Exception("unsupported image format")

    rand_str = str(uuid.uuid1())
    filename = rand_str + ext

    if QINIU_SETTINGS.Enabled:
        url, url_thumb = save_file_qiniu(binary, filename, mime)

        return url, url, url_thumb, url_thumb, mime

    else:
        from tools import save_file

        url, real_file = save_file(binary, filename, mime_type=mime)

        url_thumb = real_file_thumb = ""
        try:
            import StringIO

            from PIL import Image
            from settings import THUMB_SIZE

            im = Image.open(StringIO.StringIO(binary))
            im.thumbnail(THUMB_SIZE, Image.ANTIALIAS)

            thumb = StringIO.StringIO()
            thumb.name = filename
            im.save(thumb)
            binary = thumb.getvalue()
            thumb.close()

            mime, ext = get_img_type(binary)
            thumb_filename = rand_str + "_thumb" + ext

            url_thumb, real_file_thumb = save_file(binary, thumb_filename, mime_type=mime)
        except:
            logging.exception("save thumb error")

        return url, real_file, url_thumb, real_file_thumb, mime