我尝试打开从DB获取文件作为字节数组。 这就是我所拥有的:
从JavaScript我在控制器中调用方法查看器:
$.ajax({
type: 'GET',
url: '@Url.Action("Viewer", "Home")?fileId='+fileIdJS,
success: function (result) {
$('#preview-pdf').append(result);
},
error: function () {
console.log("Error!");
}
});
});
[HttpGet]
public ActionResult Viewer(string fileId)
{
string fileName = string.Empty;
byte[] bytes = new byte[] {};
方法查看器:
using (SqlConnection connection = new SqlConnection())
{
using (SqlCommand cmdDownload = new SqlCommand())
{
OpenConnection(connection);
cmdDownload.Connection = connection;
cmdDownload.CommandText = "SELECT file_stream, name FROM FileTable WHERE stream_id = @fileId";
cmdDownload.Parameters.AddWithValue("@fileId", fileId);
using (SqlDataReader fileDataReader = cmdDownload.ExecuteReader())
{
while (fileDataReader.Read())
{
fileName = (string)fileDataReader["name"];
bytes = (byte[])fileDataReader["file_stream"];
}
}
connection.Close();
}
}
ViewBag.b = bytes;
return PartialView("~/Views/Home/Viewer.cshtml");
}
override func viewDidLoad() {
super.viewDidLoad()
tableView.estimatedRowHeight = 70
tableView.rowHeight = UITableViewAutomaticDimension
textView.delegate = self
textView.text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."
}
extension TableViewController: UITextViewDelegate {
func textViewDidChange(_ textView: UITextView) {
let currentOffset = tableView.contentOffset
UIView.setAnimationsEnabled(false)
tableView.beginUpdates()
tableView.endUpdates()
UIView.setAnimationsEnabled(true)
tableView.setContentOffset(currentOffset, animated: false)
}
}
Viewer.cshtml (对不起代码): http://pastebin.com/peybdTad
我知道pdf.js无法使用字节数组。我尝试在uint8array中使用conver数组,但是我没有工作。有些人可能会建议我如何在pdf.js中打开一个字节数组?我很感激任何信息。