简体   繁体   English

带有django-mssql的SQL Server文件流

[英]SQL Server Filestream with django-mssql

I would like to use SQL Server Filestream feature to store files (mainly large images) from a Django application. 我想使用SQL Server Filestream功能来存储Django应用程序中的文件(主要是大图像)。 Currently I am using django-mssql as the database backend for my Django project. 目前我使用django-mssql作为我的Django项目的数据库后端。 I don't think there is any existing model field in that package that is linked to a Filestream column in SQL Server. 我认为该包中没有任何现有的模型字段链接到SQL Server中的Filestream列。

What would be the best way to use the filestream feature from Django ? 使用Django的文件流功能的最佳方法是什么? Are there any existing packages ? 有现成的套餐吗? Or do I need to implement my own custom model field, inherited from Django's built-in fields (FileField or BinaryField) ? 或者我是否需要实现自己的自定义模型字段,继承自Django的内置字段(FileField或BinaryField)?

Thanks ! 谢谢 !

Just in case anyone else is interested in using SQL Server Filestream feature, and ends up here, I started working on custom django Fields to support Filestream : a FileStreamDataField that maps to the varbinary(max) FILESTREAM type and a FileStreamField which is a virtual field that wraps the win32 Streaming API. 万一别人有兴趣使用SQL Server FILESTREAM功能,并在这里结束了,我就开始对定制工作的Django字段来支持文件流:一个FileStreamDataField映射到varbinary(max) FILESTREAM类型和FileStreamField这是一个虚拟的场包装win32 Streaming API。

import uuid

from django.db import models
from sql_filestream import FileStreamDataField, FileStreamField, UUIDField

class DocumentModel(models.Model):
    doc_id = UUIDField(default=uuid.uuid4)
    doc_content = FileStreamDataField(identifier_field='doc_id', null=True, blank=True)
    document = FileStreamField('doc_id', 'doc_content') 

You can find it with examples here : https://github.com/rparent/django-mssql-filestream It works well my use case but is certainly incomplete. 你可以在这里找到它的例子: https//github.com/rparent/django-mssql-filestream它很好用我的用例,但肯定是不完整的。 Contributions welcome ! 欢迎捐款!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM