I have the following WebUpload control that is used to insert images into a database. One of our users notified me that a certain image would not successfully upload. They sent me the image and I was also unable to upload it. The WebUpload control shows the animation as though the upload was successful, but no entry is inserted into the database. After I opened the image and did "Save As" on my machine, I was able to upload the image just fine. Any idea what could be wrong? They sent the image from a Mac computer and I am using a Windows computer, so I thought there might be some issue with the way Mac handles images. Here is the code for my WebUpload control and it's OnUploadFinishing event handler:
<ig:WebUpload ID="WebUpload1" LabelUploadButton="Add Image" runat="server" Width="95%" AutoStartUpload="true" FileSizeMetric="Auto"
ProgressUrl="IGUploadStatusHandler.ashx" MaxUploadedFiles="10" Mode="Multiple"
ShowFileExtensionIcon="true" OnUploadFinishing="WebUpload1_OnUploadFinishing"
Visible="true">
<AllowedExtensions>
<ig:FileUploadExtension Extension="jpg" />
<ig:FileUploadExtension Extension="jpeg" />
<ig:FileUploadExtension Extension="png" />
<ig:FileUploadExtension Extension="gif" />
</AllowedExtensions>
<ClientEvents OnError="onErrorHandlerWebUpload1" />
<FileExtensionIcons>
<ig:FileUploadExtensionIcon Default="true" />
</FileExtensionIcons>
</ig:WebUpload>
Protected Sub WebUpload1_OnUploadFinishing(sender As Object, e As Infragistics.Web.UI.EditorControls.UploadFinishingEventArgs) Handles WebUpload1.UploadFinishing
'Getting the temporary file name
Dim filePath As String = [String].Format("{0}{1}", e.FolderPath, e.TemporaryFileName)
'Getting the real file name
Dim destFilePath As String = Server.MapPath("Uploads") + "\" + e.FileName
'Moving file from the /Temp folder to /Uploads folder
File.Move(filePath, destFilePath)
Dim fs1 As FileStream = File.Open(destFilePath, FileMode.Open)
Dim bytBytes(fs1.Length) As Byte
fs1.Read(bytBytes, 0, fs1.Length)
fs1.Close()
Dim NewImageName As String = STR.GetBaseFileName(destFilePath)
Dim DBConn As SqlConnection = New SqlConnection(ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString)
Dim DBCMD As SqlCommand = New SqlCommand("DELETE FROM TemporaryImages WHERE CreatedBy=" & Master.StudentID, DBConn)
DBConn.Open()
DBCMD.ExecuteNonQuery()
DBConn.Close()
DBCMD.CommandText = "INSERT INTO TemporaryImages(EntryID, CreatedBy, ImageName, ImageSize, Image, ImageDescription) VALUES(@EntryID, @CreatedBy, @ImageName, @ImageSize, @Image, @ImageDescription)"
DBCMD.Parameters.Add("@EntryID", SqlDbType.BigInt, 8, "EntryID").Value = 0
DBCMD.Parameters.Add("@CreatedBy", SqlDbType.BigInt, 8, "CreatedBy").Value = Master.StudentID
DBCMD.Parameters.Add("@ImageName", SqlDbType.VarChar, 5000, "ImageName").Value = NewImageName
DBCMD.Parameters.Add("@Image", SqlDbType.VarBinary, bytBytes.Length, "Image").Value = bytBytes
DBCMD.Parameters.Add("@ImageSize", SqlDbType.BigInt, 8, "ImageSize").Value = CInt(bytBytes.Length)
DBCMD.Parameters.Add("@ImageDescription", SqlDbType.VarChar, TXTRadiologyImageDesc.Text.Length, "ImageDescription").Value = TXTRadiologyImageDesc.Text
ETVLIB4.ETV.FS.DeleteFile(destFilePath)
End Sub
Hi Eric Negem,
As far as I can see you upload the file to the server and then move it to a mapped directory and read the file as a stream which is saved as a byte stream into the data Base
First I noticed you're using OnUploadFinishing instead of OnUploadFinished, the difference is on the finish you have the file with the original name, but in both cases the file is there.
What I can suggest is to check if the file is there after the OnUploadFinished event is fired, but before you delete it? So if yes probably there is something MAC specific think with this kind of files, which should be investigated.
But if the file is not correclty uploaded the fileupload should notify you, you are saying it shows message the upload is completed, so we expect the file to be on the file system of the server. Can you check if the file is on the server so we can have more information, about this manner.
Thanks,
Todor Paskalev