How would you configure Multer to save uploaded files in a folder named "uploads"?
4 phương ánCó giải thích
Các phương án trả lời
Chọn một phương ánLời giảiChọn phương án để mở
Đáp án đúng: "destination: function (req, file, cb) { cb(null, 'uploads/'); }". Khi cấu hình multer.diskStorage với hai khoá destination và filename, hàm destination nhận req, file và callback cb; gọi cb(null, 'uploads/') nghĩa là không có lỗi (đối số đầu là null) và lưu tệp vào thư mục uploads. Lưu ý khi destination là hàm, Multer không tự tạo thư mục, nên uploads phải có sẵn. Đoạn trả về "cb(null, 'files/')" đặt đúng khoá destination nhưng ghi vào thư mục files, không phải uploads như yêu cầu. "filename: function (req, file, cb) { cb(null, 'uploads/'); }" đặt sai khoá: filename quyết định tên tệp được lưu, truyền 'uploads/' vào đó sẽ thành tên tệp chứ không chọn được thư mục. "storage: function (req, file, cb) { cb(null, 'uploads/'); }" sai vì storage là tuỳ chọn của multer() nhận một engine lưu trữ do multer.diskStorage() tạo ra, không phải một hàm callback chỉ thư mục.
Cùng chương 9
Which of the following is a standard security protocol used for secure communication over the internet?Có lời giảiCâu hỏiWhich HTTP header is used to pass the OAuth token in requests?Có lời giảiCâu hỏiWhat are the benefits of using HTTPS in a Node.js application? (Choose 3 answers)Có lời giảiCâu hỏiCả 30 câu của chủ đề30 câu