2012-07-01 1 views
1

많은 답변을 읽고 셸에서이 모든 시도했지만 내 로컬 이미지를 올바르게 저장하지 않으려면 파일을 자릅니다. 이미지 크기가 400kb 일 때 크기가 10-30kb 인 미디어 디렉토리에 파일을 만듭니다. 나는 이유를 모른다. 예를 들어 나는 경로 d : /1.png로 이미지를 가지고있다. 시도했습니다프로그래밍 방식으로 이미지를 장고에 ImageField 2 저장합니다.

from django.core.files import File 
fileObject=File(open("d:/1.png")) 
object.image.save('1.png',fileObject,True) 

fileObject.size 올바른 이미지 크기를 표시하지만 object.image.size가 올바르지 않고 파일이 저장되지 않은 내용입니다. 또한 내가 StringIO를 사용했지만,이 역시 작동하지

from django.core.files.temp import NamedTemporaryFile 
temp = NamedTemporaryFile()#with delete=True TypeError: __init__() got an unexpected keywork argument 'delete' 
temp.write(open('d:/1.png').read()) 
temp.flush() 
f=File(temp)#f.size not correct 
object.image.save('1.png',f,True) 
and object.image.size and file not correct, file not full. 

을 시도했다. 나는이 이미지를 올바르게 저장하려고하지 않습니다. 도와주세요.

답변

1

당신은 바이너리

에 FileObject = 파일로 모드를 변경해야합니다 (오픈 (: 모드 = "RB")를 "D /1.png")를