本文整理汇总了Python中django.core.files.uploadedfile.UploadedFile.name方法的典型用法代码示例。如果您正苦于以下问题:Python UploadedFile.name方法的具体用法?Python UploadedFile.name怎么用?Python UploadedFile.name使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.core.files.uploadedfile.UploadedFile
的用法示例。
在下文中一共展示了UploadedFile.name方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testFileUpload
# 需要导入模块: from django.core.files.uploadedfile import UploadedFile [as 别名]
# 或者: from django.core.files.uploadedfile.UploadedFile import name [as 别名]
def testFileUpload(self):
from django.http import QueryDict, HttpRequest
from tardis.tardis_portal.views import upload
from django.core.files import File
from django.core.files.uploadedfile import UploadedFile
from django.utils.datastructures import MultiValueDict
from os import path
# create request.FILES object
django_file = File(self.f1)
uploaded_file = UploadedFile(file=django_file)
uploaded_file.name = self.filename
uploaded_file.size = self.f1_size
post_data = [("enctype", "multipart/form-data")]
post = QueryDict("&".join(["%s=%s" % (k, v) for (k, v) in post_data]))
files = MultiValueDict({"Filedata": [uploaded_file]})
request = HttpRequest()
request.FILES = files
request.POST = post
request.method = "POST"
response = upload(request, self.dataset.id)
test_files_db = models.Dataset_File.objects.filter(dataset__id=self.dataset.id)
self.assertTrue(path.exists(path.join(self.dataset_path, self.filename)))
self.assertTrue(self.dataset.id == 1)
self.assertTrue(test_files_db[0].url == "tardis://testfile.txt")
示例2: save
# 需要导入模块: from django.core.files.uploadedfile import UploadedFile [as 别名]
# 或者: from django.core.files.uploadedfile.UploadedFile import name [as 别名]
def save(self, *args, **kwargs):
s = BytesIO()
data = zipfile.ZipFile(s,'a')
projectfiles = fileobject.objects.filter(project=self.project)
for filedata in projectfiles:
filed = filedata.filename.read()
pathAndName = str(self.project.title)+filedata.subfolder+os.path.split(str(filedata.filename))[1] #### this is where subfolders will be added to inside the zip file.
data.writestr(pathAndName, filed)
data.close()
s.seek(0)
filedata = UploadedFile(s)
filedata.name = self.project.title+".zip"
self.filename = filedata
super(zippedObjectProxy, self,).save(generate=False, *args, **kwargs)
示例3: upload_save_process
# 需要导入模块: from django.core.files.uploadedfile import UploadedFile [as 别名]
# 或者: from django.core.files.uploadedfile.UploadedFile import name [as 别名]
def upload_save_process(request):
"""
save file into local storage
"""
f = request.FILES["file"]
wrapper_f = UploadedFile(f)
name, filetype = split_name(wrapper_f.name)
obj = ProcessedFile()
obj.title = name + str(uuid.uuid4()) + "." + filetype
wrapper_f.name = obj.title
obj.file_obj = f
obj.file_type = filetype if filetype != " " else "unknown"
obj.save()
return wrapper_f
示例4: file_complete
# 需要导入模块: from django.core.files.uploadedfile import UploadedFile [as 别名]
# 或者: from django.core.files.uploadedfile.UploadedFile import name [as 别名]
def file_complete(self, file_size):
mp_file_size = sum([part.size for part in self.mp])
if file_size > self.max_file_size or mp_file_size > self.max_file_size:
raise FileExceedsSizeLimit
if file_size != mp_file_size:
raise Exception("Uploaded file size doesn't match computed file size.")
self.mp.complete_upload()
# save local metadata
self.row.size = file_size
self.row.save()
self.row.releaseLock()
uploaded_file = UploadedFile()
uploaded_file.download_key = self.row.getKey()
uploaded_file.name = self.row.filename
return uploaded_file
示例5: thumbnailify
# 需要导入模块: from django.core.files.uploadedfile import UploadedFile [as 别名]
# 或者: from django.core.files.uploadedfile.UploadedFile import name [as 别名]
def thumbnailify(filebit, sizebit):
from PIL import Image
from os.path import splitext
from django.http import HttpResponseRedirect, HttpResponse
from io import BytesIO
from django.core.files.uploadedfile import UploadedFile
import sys
browser_kind = [ ".png",".jpg",".gif" ]
jsc3d_kind = [ ".stl",".obj" ]
text_kind = [".md",".txt"]
# text_kind = [ ".txt" ]
##ext os the file extension, forced into lowercase becouse people are insane.
ext = str(splitext(str(filebit.filename))[1].lower())
response = HttpResponse(mimetype="image/png")
if ext in browser_kind:
print("filebit.filename"+str(filebit.filename.name))
img = Image.open(filebit.filename)
img.thumbnail(sizebit)
print(img)
# Create a file-like object to write thumb data (thumb data previously created
# using PIL, and stored in variable 'img')
# using PIL, and stored in variable 'thumb')
# thumb_io = BytesIO()
thumb_io = BytesIO()
img.save( thumb_io, format='png')
# Create a new Django file-like object to be used in models as ImageField using
# InMemoryUploadedFile. If you look at the source in Django, a
# SimpleUploadedFile is essentially instantiated similarly to what is shown here
thumb_file = UploadedFile(thumb_io)
thumb_file.name = str(sizebit)+"-"+str(filebit.filename)+".png"
# Once you have a Django file-like object, you may assign it to your ImageField
# and save.
return(thumb_file, "browser")
if ext in jsc3d_kind:
from selenium import webdriver
from django.conf import settings
driver = webdriver.PhantomJS()
driver.set_window_size(sizebit[0],sizebit[1]) # not optional
driver.get(settings.URL+"/thumbs/jsc3d/"+str(filebit.pk))
imagedata = driver.get_screenshot_as_base64() # save a screenshot as base64 string, the only format phantom supports that isn't disk.
import base64
from io import BytesIO
#converts the base64 encoded image data into a python file object
thumb_io = BytesIO(base64.b64decode(imagedata))
thumb_file = UploadedFile(thumb_io)
thumb_file.name = str(sizebit)+"-"+str(filebit.filename)+".png"
# thumb_file = False
return(thumb_file, "jsc3d")
if ext in text_kind:
return(False, "text")
# if ext in text_kind:
# print("filebit.filename"+str(filebit.filename.name))
# from PIL import ImageFont, ImageDraw, Image
# from django.conf import settings
# from io import StringIO
# img = Image.new("RGBA", (100,50), (255,255,255))
# draw = ImageDraw.Draw(img)
# #print(settings.URL+"/static/DejaVuSerif-Bold.ttf")
# #font = ImageFont.truetype(settings.URL+"/media/DejaVuSerif-Bold.ttf", 12)
# f = filebit.filename.file.read(64)
# draw.text((10, 0), (f.decode("utf-8")[:16]), (0,0,0) )
# draw.text((10, 10), (f.decode("utf-8")[16:32]), (0,0,0) )
# draw.text((10, 20), (f.decode("utf-8")[32:48]), (0,0,0) )
# draw.text((10, 30), (f.decode("utf-8")[48:64]), (0,0,0) )
# draw.text((10, 40), ("\t..."), (0,0,0) )
# img_resized = img.resize((sizebit), Image.ANTIALIAS)
# #img = Image.open(filebit.filename)
# #img.thumbnail(sizebit)
# print(img)
# # Create a file-like object to write thumb data (thumb data previously created
# # using PIL, and stored in variable 'img')
# # using PIL, and stored in variable 'thumb')
# thumb_io = BytesIO()
# img.save( thumb_io, format='png')
#
# # Create a new Django file-like object to be used in models as ImageField using
# # InMemoryUploadedFile. If you look at the source in Django, a
# # SimpleUploadedFile is essentially instantiated similarly to what is shown here
# thumb_file = InMemoryUploadedFile(thumb_io, None, str(sizebit)+"-"+str(filebit.filename)+".png", 'image/jpeg',
# 1, None)
#
# # Once you have a Django file-like object, you may assign it to your ImageField
# # and save.
# return(thumb_file, "browser")
#.........这里部分代码省略.........