public static byte[] GetVideoAttachmentByteArray(decimal videoAttachID) { VIDEO_ATTACHMENT doc = GetVideoAttachment(videoAttachID); byte[] bytes = doc.VIDEO_ATTACHMENT_FILE.VIDEO_ATTACH_DATA; return(bytes); }
public static VIDEO_ATTACHMENT DeleteVideoAttachment(decimal videoAttachID) { VIDEO_ATTACHMENT this_at = null; try { using (PSsqmEntities entities = new PSsqmEntities()) { VIDEO_ATTACHMENT_FILE this_atfile = (from d in entities.VIDEO_ATTACHMENT_FILE where (d.VIDEO_ATTACH_ID == videoAttachID) select d).Single(); if (this_atfile != null) { entities.DeleteObject(this_atfile); entities.SaveChanges(); } this_at = (from d in entities.VIDEO_ATTACHMENT where (d.VIDEO_ATTACH_ID == videoAttachID) select d).Single(); if (this_at != null) { entities.DeleteObject(this_at); entities.SaveChanges(); } } } catch (Exception e) { //SQMLogger.LogException(e); } return(this_at); }
protected void lbVideoId_OnClick(object sender, EventArgs e) { LinkButton lb = (LinkButton)sender; decimal attachmentId = Convert.ToDecimal(lb.CommandArgument.ToString()); VIDEO_ATTACHMENT attach = SQMDocumentMgr.GetVideoAttachment(attachmentId); tbText.Text = attach.DESCRIPTION; tbTimestamp.Text = attach.TITLE; hdnVideoAttachId.Value = attachmentId.ToString(); }
protected void rgFiles_OnEditCommand(object source, GridCommandEventArgs e) { GridEditableItem item = (GridEditableItem)e.Item; decimal attachmentId = (decimal)item.GetDataKeyValue("VideoAttachId"); VIDEO_ATTACHMENT attach = SQMDocumentMgr.GetVideoAttachment(attachmentId); tbText.Text = attach.DESCRIPTION; tbTimestamp.Text = attach.TITLE; hdnVideoAttachId.Value = attachmentId.ToString(); }
protected void rgFiles_OnDeleteCommand(object source, GridCommandEventArgs e) { GridEditableItem item = (GridEditableItem)e.Item; decimal attachmentId = (decimal)item.GetDataKeyValue("VideoAttachId"); VIDEO_ATTACHMENT attach = SQMDocumentMgr.DeleteVideoAttachment(attachmentId); this.GetUploadedFiles(_recordType, _recordId); if (OnAttachmentDelete != null && attach != null) { OnAttachmentDelete(attach); } }
public static string GetVideoAttachImageSourceString(decimal videoAttachID) { VIDEO_ATTACHMENT doc = GetVideoAttachment(videoAttachID); if (doc != null && doc.VIDEO_ATTACHMENT_FILE != null) { return(GetVideoAttachImageSourceString(doc)); } else { return(""); } }
public static string GetVideoAttachImageSourceString(VIDEO_ATTACHMENT doc) { string src = "data:image/"; //jpg;base64,"; switch (Path.GetExtension(doc.FILE_NAME)) { case ".mov": src += "mov"; break; case ".qt": src += "qt"; break; case ".wmv": src += "wmv"; break; case ".yuv": src += "yuv"; break; case ".3gp": src += "3gp"; break; case ".3g2": src += "3g2"; break; case ".nsv": src += "nsv"; break; default: src += "m4v"; break; } src += ";base64," + Convert.ToBase64String(doc.VIDEO_ATTACHMENT_FILE.VIDEO_ATTACH_DATA); return(src); }
public static VIDEO_ATTACHMENT GetVideoAttachment(decimal videoAttachID) { VIDEO_ATTACHMENT ret = null; try { using (PSsqmEntities entities = new PSsqmEntities()) { ret = (from d in entities.VIDEO_ATTACHMENT.Include("VIDEO_ATTACHMENT_FILE") where ( (d.VIDEO_ATTACH_ID == videoAttachID) ) select d).Single(); } } catch (Exception e) { //SQMLogger.LogException(e); ret = null; } return(ret); }
public static VIDEO_ATTACHMENT UpdateVideoAttachment(decimal videoAttachId, String filename, String description, String title, decimal?display_type, int recordType, decimal recordID, string sessionID, Stream file) { VIDEO_ATTACHMENT ret = null; try { using (PSsqmEntities entities = new PSsqmEntities()) { ret = (from d in entities.VIDEO_ATTACHMENT.Include("VIDEO_ATTACHMENT_FILE") where ( (d.VIDEO_ATTACH_ID == videoAttachId) ) select d).Single(); ret.RECORD_TYPE = recordType; ret.VIDEO_ID = recordID; // we might not have the record id when the attaachment is created ret.FILE_NAME = filename; ret.DESCRIPTION = description; ret.ATTACHMENT_TYPE_ID = recordType.ToString(); //To-do: what do we do when company_id is not set, like when they choose this // from the Business Org master screen? ret.UPLOADED_ID = SessionManager.UserContext.Person.PERSON_ID; ret.UPLOADED_DT = WebSiteCommon.CurrentUTCTime(); ret.TITLE = title; //d.ATTACHMENT_SCOPE = docScope; ret.SESSION_ID = sessionID; if (display_type.HasValue) { ret.DISPLAY_TYPE = display_type.Value; } if (ret.VIDEO_ATTACHMENT_FILE == null) { ret.VIDEO_ATTACHMENT_FILE = new VIDEO_ATTACHMENT_FILE(); } //read in the file contents if (file != null) { file.Seek(0, SeekOrigin.Begin); byte[] bytearray = new byte[file.Length]; int count = 0; while (count < file.Length) { bytearray[count++] = Convert.ToByte(file.ReadByte()); } ret.VIDEO_ATTACHMENT_FILE.VIDEO_ATTACH_DATA = bytearray; ret.FILE_SIZE = file.Length; } // d.DISPLAY_TYPE = Path.GetExtension(filename); entities.SaveChanges(); } } catch (Exception e) { //SQMLogger.LogException(e); ret = null; } return(ret); }
public void ProcessRequest(HttpContext context) { try { context.Response.Clear(); if (!String.IsNullOrEmpty(context.Request.QueryString["DOC_ID"])) { String document_id = context.Request.QueryString["DOC_ID"]; String fileName = "attachment"; Decimal doc_id = decimal.Parse(document_id); string fileType = ""; String mimeType = ""; if (!string.IsNullOrEmpty(context.Request.QueryString["DOC"])) { switch (context.Request.QueryString["DOC"]) { case "a": // attachment ATTACHMENT a = SQMDocumentMgr.GetAttachment(doc_id); fileType = Path.GetExtension(a.FILE_NAME); if (!string.IsNullOrEmpty(context.Request.QueryString["FILE_NAME"])) { fileName = context.Request.QueryString["FILE_NAME"]; } else { fileName += fileType; } mimeType = SQM.Website.Classes.FileExtensionConverter.ToMIMEType(fileType); context.Response.ContentType = mimeType; //context.Response.BinaryWrite(a.ATTACHMENT_FILE.ATTACHMENT_DATA); // mt - use below for video streams ? context.Response.AddHeader("content-disposition", "inline; filename=" + fileName); context.Response.AddHeader("content-length", a.ATTACHMENT_FILE.ATTACHMENT_DATA.Length.ToString()); context.Response.OutputStream.Write(a.ATTACHMENT_FILE.ATTACHMENT_DATA, 0, a.ATTACHMENT_FILE.ATTACHMENT_DATA.Length); context.Response.Flush(); break; case "v": // video VIDEO v = MediaVideoMgr.SelectVideoById(doc_id); // get the file from Azure fileType = Path.GetExtension(v.FILE_NAME); if (!string.IsNullOrEmpty(context.Request.QueryString["FILE_NAME"])) { fileName = context.Request.QueryString["FILE_NAME"]; } else { fileName += fileType; } List <SETTINGS> sets = SQMSettings.SelectSettingsGroup("MEDIA_UPLOAD", ""); string storageContainer = sets.Find(x => x.SETTING_CD == "STORAGE_CONTAINER").VALUE.ToString(); string storageURL = sets.Find(x => x.SETTING_CD == "STORAGE_URL").VALUE.ToString(); string storageQueryString = sets.Find(x => x.SETTING_CD == "STORAGE_QUERY").VALUE.ToString(); // Retrieve storage account from connection string. CloudStorageAccount storageAccount = CloudStorageAccount.Parse( CloudConfigurationManager.GetSetting("StorageConnectionString")); // Create the blob client. CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient(); // Retrieve reference to a previously created container. CloudBlobContainer container = blobClient.GetContainerReference(storageContainer); // Retrieve reference to a blob named "photo1.jpg". CloudBlockBlob blockBlob = container.GetBlockBlobReference(v.VIDEO_ID + fileType); // Save blob contents to a file. //using (var fileStream = System.IO.File.OpenWrite(@"path\myfile")) //{ // blockBlob.DownloadToStream(fileStream); //} mimeType = SQM.Website.Classes.FileExtensionConverter.ToMIMEType(fileType); context.Response.ContentType = mimeType; byte[] b = new byte[16 * 1024]; using (MemoryStream memoryStream = new MemoryStream()) { blockBlob.DownloadToStream(memoryStream); //memoryStream.WriteTo(HttpContext.Current.Response.OutputStream); //memoryStream.Close(); b = memoryStream.ToArray(); } context.Response.AddHeader("content-disposition", "inline; filename=" + fileName); context.Response.AddHeader("content-length", v.FILE_SIZE.ToString()); context.Response.BinaryWrite(b); context.Response.Flush(); //// the following is the code for finding the file in the database //VIDEO_FILE vf = MediaVideoMgr.SelectVideoFileById(doc_id); //fileType = Path.GetExtension(v.FILE_NAME); //if (!string.IsNullOrEmpty(context.Request.QueryString["FILE_NAME"])) // fileName = context.Request.QueryString["FILE_NAME"]; //else // fileName += fileType; //mimeType = SQM.Website.Classes.FileExtensionConverter.ToMIMEType(fileType); //context.Response.ContentType = mimeType; //// mt - use below for video streams ? //context.Response.AddHeader("content-disposition", "inline; filename=" + fileName); //context.Response.AddHeader("content-length", vf.VIDEO_DATA.Length.ToString()); ////context.Response.OutputStream.Write(vf.VIDEO_DATA, 0, vf.VIDEO_DATA.Length); //context.Response.BinaryWrite(vf.VIDEO_DATA); //context.Response.Flush(); //// the following is the code for finding the file on the server //fileType = Path.GetExtension(v.FILE_NAME); //fileName = context.Server.MapPath(v.FILE_NAME); //System.IO.FileInfo fileInfo = new System.IO.FileInfo(fileName); //try //{ // if (fileInfo.Exists) // { // context.Response.Clear(); // context.Response.AddHeader("Content-Disposition", "attachment;filename=\"" + fileInfo.Name + "\""); // context.Response.AddHeader("Content-Length", fileInfo.Length.ToString()); // context.Response.ContentType = "application/octet-stream"; // context.Response.TransmitFile(fileInfo.FullName); // context.Response.Flush(); // } // else // { // throw new Exception("File not found"); // } //} //catch (Exception ex) //{ // context.Response.ContentType = "text/plain"; // context.Response.Write(ex.Message); //} //finally //{ // context.Response.End(); //} break; case "va": // video attachment VIDEO_ATTACHMENT va = SQMDocumentMgr.GetVideoAttachment(doc_id); fileType = Path.GetExtension(va.FILE_NAME); if (!string.IsNullOrEmpty(context.Request.QueryString["FILE_NAME"])) { fileName = context.Request.QueryString["FILE_NAME"]; } else { fileName += fileType; } mimeType = SQM.Website.Classes.FileExtensionConverter.ToMIMEType(fileType); context.Response.ContentType = mimeType; //context.Response.BinaryWrite(a.ATTACHMENT_FILE.ATTACHMENT_DATA); // mt - use below for video streams ? context.Response.AddHeader("content-disposition", "inline; filename=" + fileName); context.Response.AddHeader("content-length", va.VIDEO_ATTACHMENT_FILE.VIDEO_ATTACH_DATA.Length.ToString()); context.Response.OutputStream.Write(va.VIDEO_ATTACHMENT_FILE.VIDEO_ATTACH_DATA, 0, va.VIDEO_ATTACHMENT_FILE.VIDEO_ATTACH_DATA.Length); context.Response.Flush(); break; default: // document DOCUMENT d = SQMDocumentMgr.GetDocument(doc_id); fileType = Path.GetExtension(d.FILE_NAME); // set this to whatever your format is of the image context.Response.ContentType = fileType; mimeType = SQM.Website.Classes.FileExtensionConverter.ToMIMEType(fileType); context.Response.ContentType = mimeType; //context.Response.AddHeader("content-length", d.DOCUMENT_DATA.Length.ToString()); //context.Response.OutputStream.Write(d.DOCUMENT_DATA, 0, d.DOCUMENT_DATA.Length); context.Response.AddHeader("content-length", d.DOCUMENT_FILE.DOCUMENT_DATA.Length.ToString()); context.Response.OutputStream.Write(d.DOCUMENT_FILE.DOCUMENT_DATA, 0, d.DOCUMENT_FILE.DOCUMENT_DATA.Length); context.Response.Flush(); break; } } } else { context.Response.ContentType = "text/html"; context.Response.Write("<p>Document not found</p>"); } } catch (Exception e) { //SQMLogger.LogException(e); } }