Tôi đã gặp sự cố liên quan đến loại truyền từ HttpInputStream đến FileStream.Không thể truyền đối tượng thuộc loại 'System.Web.HttpInputStream' để nhập 'System.IO.FileStream' MVC 3
Tôi đã làm như thế nào?
Tôi có đối tượng HttpPostedFileBase
và tôi muốn có FileStream.
tôi đã viết:
public void Test(HttpPostedFileBase postedFile) {
FileStream fileStream = (FileStream)(postedFile.InputStream); // throw exception
FileStream anotherFileStream = postedFile.InputStream as FileStream; // null
}
Tôi cũng đã cố gắng
public void Test(HttpPostedFileBase postedFile) {
Stream stream = postedFile.InputStream as Stream;
FileStream myFile = (FileStream)stream;
}
Nhưng không thành công.
Tại sao tại postedFile.InputStream
đến HttpInputStream
loại?
Và làm cách nào tôi có thể giải quyết vấn đề này?
Cảm ơn
của bạn (dòng incomming) cơ sở tập InputStream là HttpInputStream , không phải FileStream. Bạn phải đọc từ nó và lưu nó ở đâu đó, có thể vào tập tin địa phương của bạn. Đối với điều này, bạn có thể sử dụng FileStream. – OzrenTkalcecKrznaric