Hopefully this makes sense, I have create a system using members where they can login and make changed to particular doc type pages which is all working great. I also want them to be able to upload an image (With a preset name & parent folder) which doe's work fine by iframing the 'umbraco/dialogs/uploadImage.aspx' which then refers to 'Controls/Images/newImage.ascx(edited version of uploadImage.ascx)'.
It all works ok exept if your not logged into the umbraco system as a user then when the member logs in and opens up the page containing my usercontrol they are redirected to the umbraco user login page.
I need it to be able to load the usercontrol without needing to also be logged in as a user if that makes sense?
I have been attempting at getting DAMP working on my install but struggling! DAMP is all installed etc but trying to create a usercontrol with the code in the link provided just won't build.
I don't suppose you already have done this or have an example to look at?
The code in the link provided also does some things which only work in DAMP. It was more so you could use it as an example. Here is another example which is not related to DAMP:
public Media InsertMedia(int parentId, string fileName, MediaType mediaType, User adminUser, byte[] bytes, bool isImage)
{
Media media = Media.MakeNew(fileName, mediaType, adminUser, parentId);
string sql = string.Format(@"
select cpd.id as id from cmsPropertyData cpd
inner join cmsPropertyType cpt on cpd.propertytypeid = cpt.Id
inner join cmsDataType cdt on cpt.dataTypeId = cdt.nodeId
where cpd.contentNodeId = {0}
and cdt.controlId = '{1}'", media.Id, uploadField.Id);
int propertyId = SqlHelper.ExecuteScalar<int>(sql);
FileInfo file = new FileInfo(IOHelper.MapPath(SystemDirectories.Media + "/" + propertyId + "/" + fileName));
if (!file.Directory.Exists)
{
//If the directory doesn't exist then create it.
file.Directory.Create();
}
//Write the file to the media folder.
File.WriteAllBytes(file.FullName, bytes);
string umbracoFile = SystemDirectories.Media + "/" + propertyId.ToString() + "/" + fileName;
if (umbracoFile.StartsWith("~"))
{
umbracoFile = umbracoFile.TrimStart(new char[] { '~' });
}
if (media.getProperty("umbracoFile") != null)
{
media.getProperty("umbracoFile").Value = umbracoFile;
}
if (media.getProperty("umbracoExtension") != null)
{
media.getProperty("umbracoExtension").Value = Path.GetExtension(file.Name).Replace(".", string.Empty);
}
if (media.getProperty("umbracoBytes") != null)
{
media.getProperty("umbracoBytes").Value = bytes.Length;
}
if (isImage)
{
System.Drawing.Image image = System.Drawing.Image.FromFile(file.FullName);
if (media.getProperty("umbracoWidth") != null)
{
media.getProperty("umbracoWidth").Value = image.Width.ToString();
}
if (media.getProperty("umbracoHeight") != null)
{
media.getProperty("umbracoHeight").Value = image.Height.ToString();
}
//Create a thumbnail from the image.
string fileNameThumb = Path.Combine(file.Directory.FullName, file.Name.Replace(Path.GetExtension(file.Name), "_thumb.jpg"));
GenerateThumbnail(image, 100, image.Width, image.Height, fileNameThumb);
//Clean the image.
image.Dispose();
}
//Save the media file to update the xml and to make sure some event's get called.
media.Save();
media.XmlGenerate(new XmlDocument());
return media;
}
private void GenerateThumbnail(System.Drawing.Image image, int maxWidthHeight, int fileWidth, int fileHeight, string thumbnailFileName)
{
//Generate thumbnail.
float fx = fileWidth / maxWidthHeight;
float fy = fileHeight / maxWidthHeight;
//Must fit in thumbnail size.
float f = Math.Max(fx, fy); if (f < 1) f = 1;
int widthTh = (int)(fileWidth / f); int heightTh = (int)(fileHeight / f);
//Create new image with best quality settings.
Bitmap bp = new Bitmap(widthTh, heightTh);
Graphics g = Graphics.FromImage(bp);
g.SmoothingMode = SmoothingMode.HighQuality;
g.InterpolationMode = InterpolationMode.HighQualityBicubic;
g.PixelOffsetMode = PixelOffsetMode.HighQuality;
//Copy the old image to the new and resized.
Rectangle rect = new Rectangle(0, 0, widthTh, heightTh);
g.DrawImage(image, rect, 0, 0, image.Width, image.Height, GraphicsUnit.Pixel);
//Copy metadata.
ImageCodecInfo[] codecs = ImageCodecInfo.GetImageEncoders();
ImageCodecInfo codec = null;
for (int i = 0; i < codecs.Length; i++)
{
if (codecs[i].MimeType.Equals("image/jpeg"))
codec = codecs[i];
}
//Set compresion ratio to 90%.
EncoderParameters ep = new EncoderParameters();
ep.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, 90L);
//Save the new image.
bp.Save(thumbnailFileName, codec, ep);
bp.Dispose();
g.Dispose();
}
Members ability to use uploadImage.aspx
Hi all,
Hopefully this makes sense, I have create a system using members where they can login and make changed to particular doc type pages which is all working great. I also want them to be able to upload an image (With a preset name & parent folder) which doe's work fine by iframing the 'umbraco/dialogs/uploadImage.aspx' which then refers to 'Controls/Images/newImage.ascx(edited version of uploadImage.ascx)'.
It all works ok exept if your not logged into the umbraco system as a user then when the member logs in and opens up the page containing my usercontrol they are redirected to the umbraco user login page.
I need it to be able to load the usercontrol without needing to also be logged in as a user if that makes sense?
Thanks
Pete
It might be better to create a custom uploader instead of using umbraco/dialogs/uploadImage.aspx which only works when you are logged on. Have a look at how DAMP creates media: http://damp.codeplex.com/SourceControl/changeset/view/b3b45c70ce29#DigibizAdvanceMediaPicker/CreateMediaItem.aspx.cs
Jeroen
Hi Jeroen,
I have been attempting at getting DAMP working on my install but struggling! DAMP is all installed etc but trying to create a usercontrol with the code in the link provided just won't build.
I don't suppose you already have done this or have an example to look at?
Thanks
Pete
The code in the link provided also does some things which only work in DAMP. It was more so you could use it as an example. Here is another example which is not related to DAMP:
Jeroen
is working on a reply...