2013-02-18 1 views
0

Mechanize를 사용하여 양식 (파일 업로드 포함) 작성을 자동화하려고합니다. GUI 인터페이스에서 프로세스를 진행하고 파일 업로드가 정상적으로 처리되었으므로 파일이 손상되지 않았 음을 알았으므로 기계화 스크립트를 실행하면 오류가 발생합니다. 스크립트가 올바르게 실행되고 디버그에 따라 파일이 업로드되었지만 Canvas (업로드 할 서비스)는 파일을 읽을 수 없다고 말합니다. Canvas 지원팀에 연락했지만 시스템의 비표준적인 사용이기 때문에 도움을 줄 수 없습니다.Mechanize로 파일 업로드가 실패했습니다.

09 mech = Mechanize.new 
10 mech.log = Logger.new(STDOUT) 
11 mech.user_agent_alias = 'Mac Mozilla' 
12 mech.get("https://ucdenver.test.instructure.com") do |page| 
13 page.form_with(:action => "/login") do |f| 
14  user_field = f.field_with(:name => "pseudonym_session[unique_id]") 
15  user_field.value = user 
16  pwd_field = f.field_with(:name => "pseudonym_session[password]") 
17  pwd_field.value = pwd 
18 end.submit 
19 end 
20 
21 mech.get("https://ucdenver.test.instructure.com/accounts/1") do |page| 
22 page.form_with(:action => "/accounts/1/courses") do |f| 
23  course_field = f.field_with(:name => "course[name]") 
24  course_field.value = "38492" 
25 end.submit 
26 end 
27 
28 mech.page.link_with(:href => %r/settings/, 
29      :class => "settings").click 
30 
31 mech.page.link_with(:href => %r/import/, 
32      :text => %r/Import Content/).click 
33 
34 mech.page.link_with(:href => %r/imports\/migrate/, 
35      :text => %r/Import content from a content package/).click 
36 
37 mech.page.form_with(:action => %r/imports\/migrate/) do |f| 
38 export_system = "migration_settings[migration_type]" 
39 f[export_system] = "blackboard_exporter" 
40 f.file_uploads.first.mime_type = "application/zip" 
41 f.file_uploads.first.file_name = bkb_export 
42 end.submit 

캔버스 지원 서버가 반환 말했다 : 여기

은 (익명 처리 된) 스크립트입니다

Could not unzip archive file, exit status 9, message:  
[/mnt/var/web/migration_tool/data/attachment_420130214-13303-sv6ue5-0.jpg] End-of-central- 
directory signature not found. Either this file is not a zipfile, or it constitutes one 
disk of a multi-part archive. In the latter case the central directory and zipfile comment 
will be found on the last disk(s) of this archive. unzip: cannot find zipfile directory in 
one of /mnt/var/web/migration_tool/data/attachment_420130214-13303-sv6ue5-0.jpg or 
/mnt/var/web/migration_tool/data/attachment_420130214-13303-sv6ue5-0.jpg.zip, and cannot 
find /mnt/var/web/migration_tool/data/attachment_420130214-13303-sv6ue5-0.jpg.ZIP, period. 

불행하게도 그 오류가 나에게 아무 의미하지만 이상한 것 같다 스크립트가 .zip 파일을 업로드 할 때 .jpg 파일을 참조하는 것입니다. 어떤 아이디어 나 지원이라도 대단히 감사하겠습니다. 유용한 정보를 남겨두면 추가 정보를 제공해 드리겠습니다.

실제로 게이가되고 싶다면 http://canvas.instructure.com에서 무료 계정을 만들고 코드/네트워크 활동을 직접 확인하십시오.

+0

은 업로드하려는 파일 중 일부에 대해 불평하는 파일입니까? 또한 킥킥 웃음을 위해 f.file_uploads.first에서 mime_type을'application/zip'으로 설정하려고 시도했습니다 – Doon

+0

업로드하려는 .zip은 Blackboard 학습 관리 시스템에서 내보내기입니다. 나는 mim_type을 테스트했다고 생각하지만, 확실히 테스트하기 위해 다시 테스트 할 것이다. – lyonsinbeta

+0

내 질문이 업데이트되었습니다. 'mime_type'을 설정해도 효과가없는 것 같습니다. – lyonsinbeta

답변

0

당신이 파일의 모든 유형

Content-Type: application/octet-stream 

를 지정 루비 기계화 AFAIK 올바른 유형의 파일을 업로드하고 있는지 확인하십시오, 기회는 '서버의 ContentType을 확인하고 정확하게 필요한 콘텐츠 형식과 일치하지 않습니다 내가 돈이다 내가 사용하는 기계화의 정확한 버전을 기억하지 마라. 그러나 나에게 그것은 mechanize gem에서 하드 코드되었다. 그래서 당신은 machineize의 소스 코드를 거쳐 multipart/form-data 파일 요소의 content type을 하드 코딩해야한다.