Giter VIP home page Giter VIP logo

Comments (8)

lehhair avatar lehhair commented on June 19, 2024 1

前面加nginx了嘛? 如果有加的话需要调一下 nginx的 client_max_body_size

确定了一下,就是我的api不兼容大文件,确实是需要压缩一下才能用🙃

from chatgpt-web.

lehhair avatar lehhair commented on June 19, 2024 1

前面加nginx了嘛? 如果有加的话需要调一下 nginx的 client_max_body_size

为了解决这个问题我用python弄了个图片压缩服务器,在请求api的时候多一次图片压缩的请求体转发

from flask import Flask, request, jsonify
import base64
import io
from PIL import Image

app = Flask(__name__)

@app.route('/', defaults={'path': ''}, methods=['POST'])
@app.route('/<path:path>', methods=['POST'])
def compress_image(path):
    data = request.get_json()

    image_data = data.get('image')

    image_bytes = base64.b64decode(image_data)

    image = Image.open(io.BytesIO(image_bytes))

    image = image.convert('RGB')

    quality = 80

    compressed_image_buffer = io.BytesIO()

    image.save(compressed_image_buffer, format='JPEG', optimize=True, quality=quality)

    compressed_image_buffer.seek(0)

    compressed_image_base64 = base64.b64encode(compressed_image_buffer.getvalue()).decode('utf-8')

    return jsonify({'image': compressed_image_base64})

if __name__ == '__main__':
    app.run()

from chatgpt-web.

BobDu avatar BobDu commented on June 19, 2024

chagpt 自己会压缩分辨率的啊。
是大小直接超过20MB了都? 这个确实没有进一步处理。一般图片不至于这么大吧...

from chatgpt-web.

lehhair avatar lehhair commented on June 19, 2024

chagpt 自己会压缩分辨率的啊。 是大小直接超过20MB了都? 这个确实没有进一步处理。一般图片不至于这么大吧...

我也不知道为啥,实测nextweb是没问题的,小文件也没问题,4MB左右的都不行,下次我再排查一下试试吧,我用的oneapi转换的

from chatgpt-web.

BobDu avatar BobDu commented on June 19, 2024

前面加nginx了嘛? 如果有加的话需要调一下 nginx的 client_max_body_size

from chatgpt-web.

lehhair avatar lehhair commented on June 19, 2024

前面加nginx了嘛? 如果有加的话需要调一下 nginx的 client_max_body_size

加过了,不知道报错在什么地方,等我有空再次复现仔细查看一下日志再向您反馈,感谢

from chatgpt-web.

BobDu avatar BobDu commented on June 19, 2024

nodejs有合适的库能干这个么。有的话可以考虑把这个功能集成到项目里面来。

from chatgpt-web.

lehhair avatar lehhair commented on June 19, 2024

nodejs有合适的库能干这个么。有的话可以考虑把这个功能集成到项目里面来。

前端的压缩方法挺多的,我只是不会js😵

from chatgpt-web.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.