我有一个允许用户上传文件的应用程序,该文件在保存之前使用赛门铁克保护引擎进行扫描。我遇到的问题是,在使用保护引擎扫描文件之后,它们有0字节。我正努力想出解决这个问题的办法。
我尝试过这里提到的克隆解决方案:Deep cloning objects,但是我上传的文件并不都是可序列化的。我还尝试将扫描引擎类中的流重置为0,然后将其传回保存。
我已经和Symantec联系过了,他们说为这个应用程序编写的自定义连接类看起来是正确的,并且保护引擎没有抛出错误。
我愿意接受任何解决这个问题的办法。
以下是上传文件的代码:
private void UploadFiles()
{
System.Web.HttpPostedFile objFile;
string strFilename = string.Empty;
if (FileUpload1.HasFile)
{
objFile = FileUpload1.PostedFile;
strFilename = FileUpload1.FileName;
if (GetUploadedFilesCount() < 8)
{
if (IsDuplicateFileName(Path.GetFileName(objFile.FileName)) == false)
{
if (ValidateUploadedFiles(FileUpload1.PostedFile) == true)
{
//stores full path of folder
string strFileLocation = CreateFolder();
//Just to know the uploading folder
mTransactionInfo.FileLocation = strFileLocation.Split('\\').Last();
if (ScanUploadedFile(objFile) == true)
{
SaveFile(objFile, strFileLocation);
}
else
{
lblErrorMessage.Visible = true;
if (mFileStatus != null)
{ lblErrorMessage.Text = mFileStatus.ToString(); }如果有人需要,我可以提供连接类代码,但它相当大。
发布于 2015-01-22 16:16:45
在将文件传递到扫描引擎之前,您可以先获取文件的副本。
byte[] fileData = null;
using (var binaryReader = new BinaryReader(Request.Files[0].InputStream))
{
fileData = binaryReader.ReadBytes(Request.Files[0].ContentLength);
}
// pass the scanning engine
StreamScanRequest scan = requestManagerObj.CreateStreamScanRequest(Policy.DEFAULT);
//...要复制流,可以这样做:更新:
MemoryStream ms = new MemoryStream();
file.InputStream.CopyTo(ms);
file.InputStream.Position = ms.Position = 0;https://stackoverflow.com/questions/28091315
复制相似问题