2013-12-17 2 views
0

Google App Engine 응용 프로그램에서 Google Cloud Storage에 파일을 업로드하려고했습니다.Appengine (Python)의 Google Cloud Storage에 파일 업로드

class UploadHandler2(webapp.RequestHandler): 

    def PrintWithCarriageReturn(s): 
    sys.stdout.write('\r' + s) 
    sys.stdout.flush() 
    def post(self): 
form = cgi.FieldStorage(keep_blank_values = 1) 
    print form.keys() 
    fileitem = form['files'] 
if fileitem.filename: 
     filename = os.path.basename(fileitem.filename)** 

하는 사람이 어떤 조언을 주시겠습니까 : 내 서버 측 파이썬 스크립트

<form id="fileupload" action="/uploads" method="POST" enctype="multipart/form-data"> 
    <!-- Redirect browsers with JavaScript disabled to the origin page --> 
    <noscript><input type="hidden" name="redirect" value="http://2479ja.tv/jqueryupload"></noscript> 
    <!-- The fileupload-buttonbar contains buttons to add/delete files and start/cancel the upload --> 
    <div class="row fileupload-buttonbar"> 
     <div class="col-lg-7"> 
      <!-- The fileinput-button span is used to style the file input field as button --> 
      <span class="btn btn-success fileinput-button"> 
       <i class="glyphicon glyphicon-plus"></i> 
       <span>Add files...</span> 
       <input type="file" name="files" value="" required="required"> 
      </span> 
      <button type="submit" class="btn btn-primary start"> 
       <i class="glyphicon glyphicon-upload"></i> 
       <span>Start upload</span> 
      </button> 
      <button type="reset" class="btn btn-warning cancel"> 
       <i class="glyphicon glyphicon-ban-circle"></i> 
       <span>Cancel upload</span> 
      </button> 
      <button type="button" class="btn btn-danger delete"> 
       <i class="glyphicon glyphicon-trash"></i> 
       <span>Delete</span> 
      </button> 
      <input type="checkbox" class="toggle" value=""> 
      <!-- The global file processing state --> 
      <span class="fileupload-process"></span> 
     </div> 
     <!-- The global progress state --> 
     <div class="col-lg-5 fileupload-progress fade"> 
      <!-- The global progress bar --> 
      <div class="progress progress-striped active" role="progressbar" aria-valuemin="0" aria-valuemax="100"> 
       <div class="progress-bar progress-bar-success" style="width:0%;"></div> 
      </div> 
      <!-- The extended global progress state --> 
      <div class="progress-extended">&nbsp;</div> 
     </div> 
    </div> 
    <!-- The table listing the files available for upload/download --> 
    <table role="presentation" class="table table-striped"><tbody class="files"></tbody></table> 
</form>** 

입니다 : 이것은 내 클라이언트 측 업로드 양식입니다

File "/base/data/home/runtimes/python27/python27_dist/lib/python2.7/cgi.py", line 540, in __getitem__ 
raise KeyError, key KeyError: 'files' 

:하지만 난이 오류 메시지가 계속 이 코드가 잘못 되었습니까? 감사합니다

답변

1

요청을 처리하기 위해 webapp를 사용하고 있습니다. 귀하의 cgi.FieldStorage가 데이터를받지 못하는 것처럼 보입니다. 따라서 양식 객체에 '파일'이 없으므로 KeyError가 발생합니다. 웹 애플리케이션에 대한

, 당신은 할 수 있습니다 :

def post(self): 
    fileitem = self.request.POST.get('files', None) 

    fileblob = fileitem.file.read() 
    filename = fileitem.filename 
    mimetype = fileitem.type 

(해당 오류 검사와이 없음을 위해, 물론).

+0

@codegeek는 문제를 해결할 수 있었지만 이제는 다음 오류 메시지가 표시됩니다. OSError : [Errno 2] 해당 파일이나 디렉토리가 없습니다. fileitem self.request.POST.get = ('파일'없음) fileblob fileitem.file.read =() \t 파일명 = fileitem.filename \t \t \t 서비스 get_authenticated_service2 =() \t 미디어 = MediaFileUpload (파일 이름, chunksize 영역 = 여기서, ChunkSize는 재개는 = TRUE) \t #IF) (media.mimetype하지 :. \t 미디어 = MediaFileUpload (파일명 DEFAULT_MIMETYPE가 재개 = TRUE) \t 요청 = service.objects()는 (버킷을 삽입 = bucket_name, name = object_name, media_body = media). Pls 조언. 고마워요. – user3112567

관련 문제