PENGZhaoqing / CourseSelect

校园选课系统样本 (a template for course selection system by Ruby on Rails)
https://courseselect.herokuapp.com/
MIT License
105 stars 206 forks source link

下载excel文件自动跳转微软url问题 #73

Closed Rwei2016coding closed 7 years ago

Rwei2016coding commented 7 years ago

在完成下载文件功能时,使用<a href=<%="http://localhost:3000#{course.excel}"%> >aaa</a>来直接链接到文件路径下载文件。当上传的文件为非office文件,如txt等时,都能直接下载。只要上传excel等office的文件,点此下载就会跳转到一个微软在线的路径,并且报错。

log 如下:上面是上传的log,下面是下载的log

`Started PATCH "/courses/3/excel_in" for 127.0.0.1 at 2017-01-04 00:14:12 +0800
Processing by CoursesController#excel_in as HTML
  Parameters: {"course"=>{"excel"=>#<ActionDispatch::Http::UploadedFile:0x007f431249fde8 @tempfile=#<Tempfile:/tmp/RackMultipart20170104-6142-kj79es.xlsx>, @original_filename="成绩单.xlsx", @content_type="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", @headers="Content-Disposition: form-data; name=\"course[excel]\"; filename=\"\xE6\x88\x90\xE7\xBB\xA9\xE5\x8D\x95.xlsx\"\r\nContent-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet\r\n">, "excel_cache"=>""}, "commit"=>"提交", "utf8"=>"✓", "authenticity_token"=>"fD+0Q7hDdmm2cgMpJ7wBiNGxoPu3AzxbUY3jhLp6H6e8s+jNdmGZrx2UoQ57LOAr3viuP5ns/4t6yYh2qnPa7Q==", "id"=>"3"}
  Course Load (0.3ms)  SELECT  "courses".* FROM "courses" WHERE "courses"."id" = $1 LIMIT 1  [["id", 3]]
Unpermitted parameter: excel_cache
   (0.1ms)  BEGIN
  Course Load (0.3ms)  SELECT  "courses".* FROM "courses" WHERE "courses"."id" = $1 LIMIT 1  [["id", 3]]
  SQL (0.2ms)  UPDATE "courses" SET "excel" = $1, "updated_at" = $2 WHERE "courses"."id" = $3  [["excel", "___.xlsx"], ["updated_at", "2017-01-03 16:14:12.844509"], ["id", 3]]
   (14.9ms)  COMMIT
Redirected to http://localhost:3000/courses/excel
Completed 302 Found in 28ms (ActiveRecord: 15.7ms)

Started GET "/courses/excel" for 127.0.0.1 at 2017-01-04 00:14:12 +0800
Processing by CoursesController#excel as HTML
  User Load (0.3ms)  SELECT  "users".* FROM "users" WHERE "users"."id" = $1 LIMIT 1  [["id", 4]]
  Course Load (1.1ms)  SELECT "courses".* FROM "courses" WHERE "courses"."teacher_id" = $1  [["teacher_id", 4]]
  User Load (1.1ms)  SELECT "users".* FROM "users" INNER JOIN "grades" ON "users"."id" = "grades"."user_id" WHERE "grades"."course_id" = $1  [["course_id", 3]]
  Rendered shared/_sidenav.html.erb (7.7ms)
  Rendered courses/excel.html.erb within layouts/application (9.9ms)
  Rendered layouts/_header.html.erb (0.5ms)
  Rendered layouts/_content.html.erb (0.1ms)
  Rendered layouts/_footer.html.erb (0.0ms)
Completed 200 OK in 39ms (Views: 35.4ms | ActiveRecord: 2.5ms)`