mirror of
https://github.com/langgenius/dify-docs-archived.git
synced 2026-07-19 14:33:40 -04:00
插件图片上传后使用File类, 调用blob报错 Request URL is missing an 'http://' or 'https://' protocol. #139
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @jiadong696 on GitHub (Apr 8, 2025).
接受到的img1的数据是
[File(dify_model_identity='__dify__file__', url='/files/0c0c6064-1c0d-4097-a52a-ca30a849612b/file-preview?timestamp=1744164267&nonce=88faa1b997aacabec4b609a75b7f137c&sign=ZIp5FSF_Pq4buu_4OybcHpfzkiDnqTwGCpzgduoAlzE=', mime_type='image/jpeg', filename='510824197305072053.jpg', extension='.jpg', size=29529, type=<FileType.IMAGE: 'image'>), File(dify_model_identity='__dify__file__', url='/files/c81ba2c3-327a-427e-837e-2c8af75f2d6d/file-preview?timestamp=1744164267&nonce=7544f17ab3780280d2a057626875825f&sign=zhh5ile55W_xqZv6nHwqpM5ldWEujrYIUrioZ4D5qDU=', mime_type='image/jpeg', filename='510824199402152556.jpg', extension='.jpg', size=62689, type=<FileType.IMAGE: 'image'>), File(dify_model_identity='__dify__file__', url='/files/a5af6b6c-fcb7-445a-aa76-473da68ac601/file-preview?timestamp=1744164267&nonce=6d518da07d0b04cb40d8a55b7413e8cc&sign=Wgz1tLlMezfZqouZYqztKXTtqPSGtPuOxtM8h40B9Vs=', mime_type='image/jpeg', filename='ceshi.jpg', extension='.jpg', size=73207, type=<FileType.IMAGE: 'image'>)]我调用 img.blob 提示httpx.UnsupportedProtocol: Request URL is missing an 'http://' or 'https://' protocol错误
请问是插件版本低了还是什么原因导致的? 我上传的本地文件, 这个如何修改, 谢谢指导
@dosubot[bot] commented on GitHub (Apr 8, 2025):
The error you're encountering is due to the URLs in the
Fileobjects missing the protocol (http://orhttps://). Theblobproperty method in theFileclass attempts to fetch the file content via an HTTP GET request, which requires a complete URL with a protocol.To resolve this issue, you need to ensure that the URLs include the protocol. You can prepend the base URL to the
urlattribute of eachFileobject. The dify-docs repository provides a configuration setting for specifying the base URL through the secretDIFY_BASE_URL, which defaults tohttps://api.dify.ai/v1[1].Here's a possible solution:
https://api.dify.ai/v1.urlattribute of eachFileobject before accessing theblobproperty.For example:
This should resolve the error by ensuring that all URLs are complete and valid for HTTP requests.
To continue talking to Dosu, mention @dosu.
Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Bug Report | Other
@jiadong696 commented on GitHub (Apr 8, 2025):
我获取dify_plugin模块中的config目录下的config文件里面DifyPluginEnv类下REMOTE_INSTALL_HOST, 对这个进行调用,提示我找不到, 报错 raise AttributeError(item)
AttributeError: REMOTE_INSTALL_HOST
但是我在.env配置中设置了对应的REMOTE_INSTALL_HOST, 但是他无法获取是怎么回事呢?
@jiadong696 commented on GitHub (Apr 8, 2025):
我需要写死当前http的dify路由吗 我能从那个配置获取图片的前缀URL么?
@dosubot[bot] commented on GitHub (Apr 8, 2025):
对于第一个问题,
AttributeError: REMOTE_INSTALL_HOST表示在DifyPluginEnv类中无法找到REMOTE_INSTALL_HOST。确保在代码中正确地访问环境变量。通常,环境变量可以通过os.environ来访问。例如:确保
.env文件中的变量已被正确加载到环境中。可以使用python-dotenv库来加载.env文件:对于第二个问题,关于获取图片的前缀 URL,
dify-docs仓库中没有直接提供构建或检索文件资源基础 URL 的方法或工具。你可以在配置中定义一个基础 URL,然后在代码中使用它来构建完整的 URL。例如:确保在代码中使用正确的基础 URL 来构建完整的文件访问路径。
To continue talking to Dosu, mention @dosu.
Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Bug Report | Other
@jiadong696 commented on GitHub (Apr 9, 2025):
生成.difypkg插件文件后 .env文件不会包含在插件中, 所以正式上线是无法获取通用地址的, 这个怎么解决呢 不可能我测试服生成一个difypkg, 生产环境生成一个, 正式服生成一个, 所以这个还有其他方式获取吗
@dosubot[bot] commented on GitHub (Apr 9, 2025):
在生成
.difypkg插件文件后,.env文件不会包含在插件中,因此在正式环境中无法直接获取通用地址。为了解决这个问题,可以考虑以下方法:使用环境变量管理服务:在生产环境中,使用环境变量管理服务(如 AWS Secrets Manager、Azure Key Vault 或 HashiCorp Vault)来存储和管理敏感信息和配置。这些服务可以安全地存储环境变量,并在应用启动时动态加载。
配置文件:在生产环境中,使用配置文件来存储必要的配置信息。确保这些文件在部署时被正确加载,并且不包含在插件包中。可以使用
python-dotenv或类似工具在应用启动时加载这些配置。环境变量注入:在部署过程中,通过 CI/CD 管道或部署脚本将必要的环境变量注入到运行环境中。这种方法可以确保在不同环境中使用相同的插件包,而不需要在每个环境中生成不同的包。
动态配置服务:实现一个配置服务,应用在启动时从该服务获取必要的配置信息。这种方法可以使配置管理更加灵活,并且可以在不重新部署应用的情况下更新配置。
通过这些方法,可以在不同环境中使用相同的插件包,同时确保能够获取到正确的配置信息。
To continue talking to Dosu, mention @dosu.
Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Bug Report | Other