将文件上传到Django后端时,无法获取FileVersion信息?

时间:2019-03-27 07:01:50

标签: python django django-models

我正在尝试将文件上传到我的云。上传此文件时,我还需要获取其版本信息。

一个示例 POST 请求( Body )如下所示(这没有获取 FileVersionInfo 的脚本):

[POST Data[1]

现在,当我尝试上传文件时,出现以下错误:

https://developers.google.com/youtube/v3/docs/videos/list#id

有人可以解释我该如何处理(找不到文件 错误)吗?我采用这种方法可能是错误的,但是有人可以建议我采用更好的方法吗?

我的django模型定义如下:

import os
import win32api

from django.db import models
from custom.storage import AzureMediaStorage as AMS

class File(models.Model):
    '''
    File model
    '''
    file = models.FileField(blank=False, storage=AMS(), null=False)
    filetype = models.CharField(max_length=25, default="")
    timestamp = models.DateTimeField(auto_now_add=True)
    version = models.CharField(max_length=25, default="")
    remark = models.CharField(max_length=100, default="")


    @property
    def get_file_type(self):
        return os.path.splitext(str(self.file))[1]

    @property
    def get_version(self):
        """
        Read all properties of the given file and return them as a dictionary.
        """
        props = {'FileVersion': None}

        # For Debugging (This returns False) 
        print("Is the file there? ", os.path.isfile(str(self.file)) )

        # To get the FileVersion information
        fixedInfo = win32api.GetFileVersionInfo(str(self.file), '\\')
        print("FixedInfo: ", fixedInfo)

        props['FixedFileInfo'] = fixedInfo
        props['FileVersion'] = "%d.%d.%d.%d" % (fixedInfo['FileVersionMS'] / 65536,
                fixedInfo['FileVersionMS'] % 65536, fixedInfo['FileVersionLS'] / 65536,
                fixedInfo['FileVersionLS'] % 65536)

        # For Debugging
        print("Type of props['FileVersion']:", type(props['FileVersion']))
        print("props['FileVersion']: ", props['FileVersion'])

        return props['FileVersion']

    def save(self, *args, **kwargs):
        self.filetype = self.get_file_type
        self.version = self.get_version
        super(File, self).save(*args, **kwargs)

0 个答案:

没有答案