Closed Rwei2016coding closed 7 years ago
在完成下载文件功能时,使用<a href=<%="http://localhost:3000#{course.excel}"%> >aaa</a>来直接链接到文件路径下载文件。当上传的文件为非office文件,如txt等时,都能直接下载。只要上传excel等office的文件,点此下载就会跳转到一个微软在线的路径,并且报错。
<a href=<%="http://localhost:3000#{course.excel}"%> >aaa</a>
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"} [1m[35mCourse Load (0.3ms)[0m SELECT "courses".* FROM "courses" WHERE "courses"."id" = $1 LIMIT 1 [["id", 3]] Unpermitted parameter: excel_cache [1m[36m (0.1ms)[0m [1mBEGIN[0m [1m[35mCourse Load (0.3ms)[0m SELECT "courses".* FROM "courses" WHERE "courses"."id" = $1 LIMIT 1 [["id", 3]] [1m[36mSQL (0.2ms)[0m [1mUPDATE "courses" SET "excel" = $1, "updated_at" = $2 WHERE "courses"."id" = $3[0m [["excel", "___.xlsx"], ["updated_at", "2017-01-03 16:14:12.844509"], ["id", 3]] [1m[35m (14.9ms)[0m 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 [1m[36mUser Load (0.3ms)[0m [1mSELECT "users".* FROM "users" WHERE "users"."id" = $1 LIMIT 1[0m [["id", 4]] [1m[35mCourse Load (1.1ms)[0m SELECT "courses".* FROM "courses" WHERE "courses"."teacher_id" = $1 [["teacher_id", 4]] [1m[36mUser Load (1.1ms)[0m [1mSELECT "users".* FROM "users" INNER JOIN "grades" ON "users"."id" = "grades"."user_id" WHERE "grades"."course_id" = $1[0m [["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)`
在完成下载文件功能时,使用
<a href=<%="http://localhost:3000#{course.excel}"%> >aaa</a>
来直接链接到文件路径下载文件。当上传的文件为非office文件,如txt等时,都能直接下载。只要上传excel等office的文件,点此下载就会跳转到一个微软在线的路径,并且报错。log 如下:上面是上传的log,下面是下载的log