CSLA.NET with binary objects i.e. JPEGS, MP3 & AVI

CSLA.NET with binary objects i.e. JPEGS, MP3 & AVI

Old forum URL: forums.lhotka.net/forums/t/3084.aspx


Pixel posted on Monday, June 25, 2007

Hi,

Im quite new to CSLA and serious enterprise development in general.  I'm in the process of developing an application to manage digital assets be they pictures, images or audio.   My reasons for using CSLA are more to do with consistency of the code than just the scalability.  I want my code to be easily maintained when I move on to other projects.

My question at this stage in my research is CSLA suited to handling binary objects like those discussed?   It is a web app that allows users to upload their files and at that point they are manipulated and stored.   In fact lets say YouTube is similar but with just video.   Would you attempt to build 'you tube' with CSLA.NET?

Youtube needs scalability and the ability to record data such as tags and comments etc against each piece of video.......but would the manipulation of the video on initial upload be somehting completely seperate to CSLA?

Sorry if I'm rambling.

Pixel. 

RockfordLhotka replied on Monday, June 25, 2007

I guess it depends on what you mean by "manipulated'.

I'm assuming you aren't talking about actually manipulating the content, as there are specialized tools for that. So you are talking about taking the uploaded file, putting it into the correct directory on the server and associating metadata with that file?

If that's the case then CSLA should be quite helpful. All that metadata is merely data entered (somehow) by the user and stored/retrieved from a database or other data store, and that's exactly what CSLA is designed for.

Pixel replied on Monday, June 25, 2007

Thanks Rocky.......

I guess I'm looking at the scenario, for example, of a picture being uploaded to a web site and using CSLA.NET to manage extracting the meta data and recording it in the database and then kick starting any manipulation such as resizing or water marking.   I realise CSLA would have to collaborate with other objects to physically extract the metadata string or do the resizing.   I just wanted to know if pumping a raw binary stream/object into a CSLA BO direct from a HTML/ASP.NET form is overkill.

CSLA.NET will be extremely useful in the management of the users, tagging, general business management and eventual e-commerce components but I just wanted it to own the upload process of the application as well.

Reading your response it sure looks like this is going to be worth further investigation.  Am I on the right lines?

  

RockfordLhotka replied on Monday, June 25, 2007

I’m not a web expert, so bear with me here, but don’t all the standard file upload tools upload to some file on the web server? It seems like a bad idea to upload a file into an in-memory object on the server; CSLA or not…

 

From a technical perspective, it is quite possible for a CSLA object to hold binary data – that’s what an int is after all J   The broader concern I’d have is whether it is wise to load large binary blobs into memory at all, and if you do so, how to manage them so server memory doesn’t become an issue.

 

Rocky

Pixel replied on Monday, June 25, 2007

I'm a little confused now.  You're undoubtedly more knowledgable than I am but  my understanding based on years of ASP development is that the browser just delivers a binary file to the server via HTTP.  The server running a script or exectuting .NET has to decide what to do with the data.  Its not automatically written to disk.   You 'had' to buy third party tools to do that.   Is it not in memory at the point before being written to to the location on disk?

My prototypes have been extracting the upload from the HTTP stream and resizing etc all on one thread.  I know thats bad.

I guess I should be looking at getting the files written to disk as soon as possible in the upload and then on a different thread doing any resizing?

Thanks for allowing me to go a little off-topic.



 

 

JoeFallon1 replied on Monday, June 25, 2007

I use CSLA and ASP.Net to upload images (and files and ...).

I use the Binary data from the upload and store it in a CSLA BO.

===================================================================================

e.g. BO Code:

Protected mAttdoc As Byte() = Nothing

Public Overridable Property Attdoc() As Byte()
Get
  Return mAttdoc
End Get

Set(ByVal Value As Byte())
  mAttdoc = Value
  PropertyHasChanged(
"Attdoc")
End Set
End Property

'fetch the binary data from the database:
Protected Overridable Sub FetchData(ByVal dr As SafeDataReader)
With dr
If .Read = True Then
  mAttdoc = CType(.Item("attdoc"), Byte())
  mContenttype = Trim(.GetString(
"contenttype"))
End If
End With
End Sub

'save the binary data to the database. (Or to a folder on the web server or...)

===================================================================================

Web Page Code:

Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click

'other code here

If mBO.IsNew AndAlso FileUpload.PostedFile IsNot  Nothing AndAlso FileUpload.PostedFile.ContentLength > 0 Then

  mBO.AttachDoc.contenttype = FileUpload.PostedFile.ContentType
  mBO.AttachDoc.attdoc = GetBinaryData(FileUpload.PostedFile, FileUpload.PostedFile.ContentLength)
End If

'other code here

End Sub

===================================================================================

Private Function GetBinaryData(ByRef theFile As System.Web.HttpPostedFile, ByVal ContentLength As Integer) As Byte()

Dim Temp(ContentLength) As Byte
theFile.InputStream.Read(Temp, 0, ContentLength)
Return Temp
End Function

===================================================================================

Joe

 

Pixel replied on Monday, June 25, 2007

You learn something new everyday.....I just found this.  ( I dont work for powupload.com) !!!!

ASP.NET has native object that stores uploaded files. Native ASP.NET object has one seriouse disadvantage: It uses memory equal to files size. If you uploads large files you can get "out of memory" error.

May be you will be interested in our another product PowUpload ASP.NET upload control. PowUpload handles and stores the contents of the POST request to a file on the server hard disk rather than loading it into memory as the built-in ASP.NET upload support does. PowUpload provides rich server-side progress indicator that lets users to monitor the progress of their uploads and some ather advanced features.

So it looks like Rocky was right 'again'.  I need to get this right as I might very well have 100 people at the sametime uploading images that all need to be resized on the fly.

Anybody else got experience with ASP.NET uploads and CSLA.NET?

Copyright (c) Marimer LLC