We are using FileVista and really like it's simplicity. But we have a requirement to store the uploaded files as binary data (IMAGE/BLOB) in SQL Server.
Is there any way that we could do this with the current version or lese, do you have any plans to support this in a future release?
I've recently read Darren Johnstones great post about how to upload big files to SQL Server in chunks:
http://darrenjohnstone.net/2008/07/05/aspnet-file-upload-revisited-part-3-uploading-to-sql-server/
Ideally I would like for FileVista to support this ou-of-the-box.
Any comments on this?
Cheers,
Joakim
Joakim Westin
8/5/2008 5:49 AM
Actually our upload module has a upload strorage provider feature which allows you to plugin your own storage handling code (like DB storage). First you need to add these lines to web.config:
<configSections>
<sectionGroup name="system.web">
<section name="GleamTech.Web.FileTransfer" type="GleamTech.Web.FileTransfer.FileTransferSection, GleamTech.Web.FileTransfer"/>
</sectionGroup>
</configSections>
<system.web>
<httpModules>
<add name="GleamTech.Web.FileTransfer.UploadHttpModule" type="GleamTech.Web.FileTransfer.UploadHttpModule, GleamTech.Web.FileTransfer"/>
</httpModules>
<GleamTech.Web.FileTransfer>
<uploadStorageProvider type="YourProviderClass, YourProviderNamespace" parameter="parameter like connection string etc" />
</GleamTech.Web.FileTransfer>
</system.web>
Here is a sample code for YourProviderClass:
class YourProviderClass : UploadStorageProvider
{
private FileVistaRootFolder rootFolder;
private string relativePath;
private string physicalPath;
//initialize according to parameter (connection string)
public override void Initialize(string parameter)
{
}
//Upload (may contain multiple files) starts, determine paths etc.
public override void StartUpload()
{
int rootFolderID = Convert.ToInt32(this.Context.Request.QueryString["rootFolderID"]);
string relativePath = this.Context.Request.QueryString["relativePath"];
relativePath = (relativePath == null) ? String.Empty : relativePath;
FileVistaRootFolder rootFolder = FileVistaControl.SessionRootFolders[rootFolderID];
this.physicalPath = rootFolder.MapPath(relativePath);
this.rootFolder = rootFolder;
this.relativePath = relativePath;
}
//A file is started ,create and return a file stream
public override Stream StartFile()
{
//FileStream fileStream = new database stream;
//You can save information about file here
this.UploadProgress.CurrentFile.ProviderData = filePath;
return fileStream;
}
//A file is finished, you do some final things here
public override void CompleteFile()
{
//You can get back information about file here
string fileInfo = this.UploadProgress.CurrentFile.ProviderData.ToString();
}
//All files finished
public override void CompleteUpload()
{
if (this.UploadProgress.Status == UploadStatus.Completed)
{
else //delete files if not complete
{
if (this.UploadProgress.UploadedFiles != null)
{
try
{
foreach (UploadedFile uploadedFile in this.UploadProgress.UploadedFiles)
{
if (!uploadedFile.IsUploadCompleted)
{
string filePath = uploadedFile.ProviderData.ToString();
if (File.Exists(filePath))
File.Delete(filePath);
}
}
}
catch
{
}
}
}
}
Cem Alacayir
8/8/2008 2:55 PM
Thanks for the suggestion. I will look into that.
Joakim Westin
8/11/2008 2:01 AM