Programatically upload image/media item - what am I missing?
Hi fellow devs,
I'm trying to upload an image (System.Drawing.Image) to Umbraco, but when I'm running the code, the only thing that gets uploaded is the thumbnail of the image. I have checked and double-checked the path to the created media item and it should be correct! It feels like I have missed something, somewhere. Any help/hint on this is greatly appreciated!
I'm asuming you're using a form to submit the image. Does it have the "accept" attribute set were you specify the mime-type of the content you want to upload? It's a long shot but I remember having kind of the same problem with some PDF upload using the API a year ago or something.
What I am trying to do is to make an image cropper to the frontend so the following steps will be like this:
Upload the original image to umbraco using an Upload asp.net control (works just fine, the image gets uploaded etc)
On postback: set an asp:Image to the uploaded picture and envoke the cropping tool (using jCrop for this)
When the cropping area is selected and the Crop button (regular asp:Button) is clicked, upload the cropped image and delete the original one.
My btnCrop_Click event looks like this:
protected void btnCrop_Click(object sender, EventArgs e)
{
string ImageName = imgUrl.Text;
int w = Convert.ToInt32(W.Value);
int h = Convert.ToInt32(H.Value);
int x = Convert.ToInt32(X.Value);
int y = Convert.ToInt32(Y.Value);
byte[] CropImage = Crop(ImageName, w, h, x, y);
using (MemoryStream ms = new MemoryStream(CropImage, 0, CropImage.Length))
{
ms.Write(CropImage, 0, CropImage.Length);
using (System.Drawing.Image CroppedImage = System.Drawing.Image.FromStream(ms, true))
{
string SaveTo = imgName.Text;
CroppedImage.Save(ms, CroppedImage.RawFormat);
Media m = UmbracoSaveCroppedImage(CroppedImage);
pnlCrop.Visible = false;
pnlCropped.Visible = true;
imgCropped.ImageUrl = m.getProperty("umbracoFile").Value.ToString();
}
}
}
Where I call the method UmbracoSaveCroppedImage(System.Drawing.Image image); I posted in my first post here.
Is it possible at all the grab a regular System.Drawing.Image from the frontend (my asp:Image control) and upload the image to umbraco, or do I have to use an Upload control for this?
Programatically upload image/media item - what am I missing?
Hi fellow devs,
I'm trying to upload an image (System.Drawing.Image) to Umbraco, but when I'm running the code, the only thing that gets uploaded is the thumbnail of the image. I have checked and double-checked the path to the created media item and it should be correct! It feels like I have missed something, somewhere. Any help/hint on this is greatly appreciated!
My code:
Thanks a lot in advance!
Merry xmas!
Hi Bo
I'm asuming you're using a form to submit the image. Does it have the "accept" attribute set were you specify the mime-type of the content you want to upload? It's a long shot but I remember having kind of the same problem with some PDF upload using the API a year ago or something.
/Jan
Hi Jan,
Thanks for your reply!
What I am trying to do is to make an image cropper to the frontend so the following steps will be like this:
Right, it works now ;)
Sometimes it helps to take a 10 min break away from the screen!
What I needed was to call the save method on the croppedImage: croppedImage.Save(fullFilePath);
is working on a reply...