首页 > 解决方案 > 从 Thumbor 读取图像

问题描述

我在我的电脑上Thumbor用作Docker图像。我可以将图像保存到 Thumbor,但无法从 URL 读取图像

这是我用来保存文件的方法

    var httpClient = new HttpClient();
    var httpContent = new ByteArrayContent(FileToByteArray(filename));            
    HttpResponseMessage response = null;
    try
    {
        httpContent.Headers.Add("Content-Type", "image/jpg");
        response = httpClient.PostAsync("http://localhost:32773/image", httpContent).Result;
    }
    catch (HttpRequestException ex)
    {

    }

我正在使用邮递员的这个 URL,它会引发错误400Bad Request

http://localhost:32773/1.jpg

我在 URL 中遗漏了什么吗?任何人都可以帮助我提供示例 C# 代码吗?感谢你的帮助!

标签: c#thumbor

解决方案


正确的请求 URL 是:

http://localhost:32773/image/<the original location response>

这是存储图像的示例

POST http://192.168.2.48:8082/image

HTTP/1.1 201 Created
Date: Thu, 05 Mar 2020 11:56:12 GMT
Content-Length: 0
Content-Type: text/html; charset=UTF-8
Location: /image/8ad1c65a3e6341cfb231b1faf438fc0e/image.jpg
Server: TornadoServer/4.5.3

获取相同的图像:

GET http://192.168.2.48:8082/image/8ad1c65a3e6341cfb231b1faf438fc0e/image.jpg

简而言之:确保在存储图像时存储响应标头中的位置信息


推荐阅读