Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Upload images via module?
olaj
#1 Posted : Wednesday, February 03, 2010 6:36:09 PM(UTC)
Rank: Advanced Member
Groups: Registered

Joined: 12/31/2009(UTC)
Posts: 79
Location: Göteborg, Sweden
I am trying to upload some images via a module but i get an error that seems a bit like a bug.

My plan is to upload a image to a binary folder and then add the image to item. But i get stuck at the upload part. I have tried:

Code:
CmsContext.ContentService.AddContent("RecipeImage", GetUserName(), newImage, Request.Files, null);


But i get an error that says:

Quote:
Invalid object name 'Cms_Hemmakonditori_RecipeImageSchema'.


Is this a bug or am i dooing something wrong? Can i do this on some other way? I had some problems with file attachments also (that i reported in the bugs forum).
jifeng
#2 Posted : Wednesday, February 03, 2010 7:28:25 PM(UTC)
Rank: Administration
Groups: Administrators, Registered

Joined: 9/3/2009(UTC)
Posts: 1,394
Location: Xiamen China
The ContentService can only add the text content, right now we have not content api to add binary content.
Regards,

Jifeng Huang

Kooboo Team

Microsoft ASP.NET MVP
olaj
#4 Posted : Wednesday, February 03, 2010 8:11:30 PM(UTC)
Rank: Advanced Member
Groups: Registered

Joined: 12/31/2009(UTC)
Posts: 79
Location: Göteborg, Sweden
Okej, so there is no way for us to let a user upload content from a form on our webpage? Do you recommend any alternative solution?

Should i just handle the upload myself and then use the "UserKey" or ContentId to name the file and link it manually?
jifeng
#5 Posted : Wednesday, February 03, 2010 8:32:40 PM(UTC)
Rank: Administration
Groups: Administrators, Registered

Joined: 9/3/2009(UTC)
Posts: 1,394
Location: Xiamen China
You can use the text schema with a file column or "Include Files"
Regards,

Jifeng Huang

Kooboo Team

Microsoft ASP.NET MVP
olaj
#6 Posted : Wednesday, February 03, 2010 8:34:46 PM(UTC)
Rank: Advanced Member
Groups: Registered

Joined: 12/31/2009(UTC)
Posts: 79
Location: Göteborg, Sweden
Ahh. I thought about that but i didn't understand how to upload a file to it. I guess i cant just:

newRecipe.Add("UserKey", Title.ToLower().ToUrlCompatible());
newRecipe.Add("Title", Title);
newRecipe.Add("Description", Description);
newRecipe.Add("Rating", "3");
newRecipe.Add("AddedBy", GetUserName());
newRecipe.Add("DefaultImage", Request.Files[0]);

var contentRecipe = CmsContext.ContentService.AddContent("Recipes", GetUserName(), newRecipe, Request.Files, combined);

Could you help me with some code how to do this?
jifeng
#7 Posted : Wednesday, February 03, 2010 8:39:45 PM(UTC)
Rank: Administration
Groups: Administrators, Registered

Joined: 9/3/2009(UTC)
Posts: 1,394
Location: Xiamen China
For example:

Code:

newRecipe.Add("Title", Title);
newRecipe.Add("Description", Description);
newRecipe.Add("Rating", "3");
newRecipe.Add("AddedBy", GetUserName());
// newRecipe.Add("DefaultImage", Request.Files[0]);
// Don't need to set the file field, it will set the file url after file saved. It required the file key equal to Column name, for example:
<input type="file" name="DefaultImage"/>

var contentRecipe = CmsContext.ContentService.AddContent("Recipes", GetUserName(), newRecipe, Request.Files, combined);
Regards,

Jifeng Huang

Kooboo Team

Microsoft ASP.NET MVP
olaj
#8 Posted : Wednesday, February 03, 2010 10:03:21 PM(UTC)
Rank: Advanced Member
Groups: Registered

Joined: 12/31/2009(UTC)
Posts: 79
Location: Göteborg, Sweden
Nice! You guys are to smart sometimes. It's so easy i do not get it ;)
olaj
#9 Posted : Wednesday, February 03, 2010 11:35:14 PM(UTC)
Rank: Advanced Member
Groups: Registered

Joined: 12/31/2009(UTC)
Posts: 79
Location: Göteborg, Sweden
But it still doesn''t work.

Everything looks good when i debug the module. I see the file in the Request.Files collection. It has a content-length and it's at position 0. When i have saved my item and look at the item in KooBoo i see a URL to the image and everything looks fine.

But when i try to display the image on the webpage it doesnt work. It works fins if i upload the image via KooBoo but not for the ones i uploaded from my custom form.

Any hints?
jifeng
#10 Posted : Thursday, February 04, 2010 8:57:41 AM(UTC)
Rank: Administration
Groups: Administrators, Registered

Joined: 9/3/2009(UTC)
Posts: 1,394
Location: Xiamen China
HI

Please check if the image url start with "~/", if it so please use the "Url.Content(relativeUrl)" to resolve the relative url.
Regards,

Jifeng Huang

Kooboo Team

Microsoft ASP.NET MVP
jifeng
#3 Posted : Thursday, February 04, 2010 9:38:05 AM(UTC)
Rank: Administration
Groups: Administrators, Registered

Joined: 9/3/2009(UTC)
Posts: 1,394
Location: Xiamen China
jifeng wrote:
The ContentService can only add the text content, right now we have not content api to add binary content.


We have added a method to add binary content, you can use in next version:

Code:


public Cms_Content AddBinaryContent(string folderName, string userName, NameValueCollection values, HttpPostedFileBase file, bool published)

Regards,

Jifeng Huang

Kooboo Team

Microsoft ASP.NET MVP
olaj
#11 Posted : Thursday, February 04, 2010 7:59:13 PM(UTC)
Rank: Advanced Member
Groups: Registered

Joined: 12/31/2009(UTC)
Posts: 79
Location: Göteborg, Sweden
jifeng: Nice with the feature in the new vesion!

But for now it still doesn't work. When i look into the ContentFiles\MySite\Content\MySchema\ folder i see that it doesn't create a folder (or an image) if i upload via a custom form. As i said it works if i do it via the KooBoo Admin GUI.
zguoqi
#13 Posted : Thursday, February 04, 2010 9:33:08 PM(UTC)
Rank: Administration
Groups: Registered, Administrators

Joined: 9/2/2009(UTC)
Posts: 690
Location: xiamen
olaj,

I am testing the new version at this moment. Seems like we will be releasing a new version in a week including some updates and also the GUI updater as you mentioned in another thread.

After this version, we hope to do some marketing activities including submit to the windows application gallery. And also I need to write a lot of documents.
Regards,

Vincent

Kooboo Team
jifeng
#12 Posted : Friday, February 05, 2010 11:19:14 AM(UTC)
Rank: Administration
Groups: Administrators, Registered

Joined: 9/3/2009(UTC)
Posts: 1,394
Location: Xiamen China
olaj wrote:
jifeng: Nice with the feature in the new vesion!

But for now it still doesn't work. When i look into the ContentFiles\MySite\Content\MySchema\ folder i see that it doesn't create a folder (or an image) if i upload via a custom form. As i said it works if i do it via the KooBoo Admin GUI.


Here is the sample to add content with files:
Code:

<%@ Control Language="C#" Inherits="Everest.CmsServices.MvcHelper.CmsUserControl" %>

<script runat="server">
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
if (Request.HttpMethod.ToLower() == "post")
{
ContentService.AddContent("News", "", Request.Form, ViewContext.RequestContext.HttpContext.Request.Files);
}
}
</script>

<form enctype="multipart/form-data" method="post">
<div>
Title:
<input type="text" name="Title" />
</div>
<div>
Image:
<input type="file" name="Image" />
</div>
<div>
Other Files:<input type="file" name="file1" />
</div>
<div>
<input type="submit" value="Submit" />
</div>
</form>



File Attachment(s):
TestSite_2010_02_05_11_22_26.zip (2,451kb) downloaded 15 time(s).

You cannot view/download attachments. Try to login or register.
Regards,

Jifeng Huang

Kooboo Team

Microsoft ASP.NET MVP
olaj
#14 Posted : Friday, February 05, 2010 8:30:44 PM(UTC)
Rank: Advanced Member
Groups: Registered

Joined: 12/31/2009(UTC)
Posts: 79
Location: Göteborg, Sweden
Ahh!

Now i get it. it didn't work when i debuged it from the module. Worked fine when i run the module in the KooBoo context!
salman
#15 Posted : Thursday, March 25, 2010 9:08:17 PM(UTC)
Rank: Member
Groups: Registered

Joined: 2/13/2010(UTC)
Posts: 20
Location: Rotterdam, Amsterdam, The Netherlands
ls

I have more or less a similar question.

I have a text schema with a reference to a binary schema.

How can I (through module development):

1) let user select a binary and attach to a content item
2) change that selected binary?

Thank you in advanced.

Salman
zguoqi
#16 Posted : Thursday, March 25, 2010 10:16:25 PM(UTC)
Rank: Administration
Groups: Registered, Administrators

Joined: 9/2/2009(UTC)
Posts: 690
Location: xiamen
Salman,

It seems like we do not have enough available API methods at this moment, updating of category or reference content is bit difficult now. We should try to provide more methods in the coming version.
Regards,

Vincent

Kooboo Team
salman
#17 Posted : Thursday, March 25, 2010 10:50:07 PM(UTC)
Rank: Member
Groups: Registered

Joined: 2/13/2010(UTC)
Posts: 20
Location: Rotterdam, Amsterdam, The Netherlands
Thank you for your quick reply.

Is it possible to talk directly to the database? Or do I overlook something this way?

and it is true that i only have to modify the Cms.ContentFile table?

Salman
jifeng
#18 Posted : Friday, March 26, 2010 8:20:44 PM(UTC)
Rank: Administration
Groups: Administrators, Registered

Joined: 9/3/2009(UTC)
Posts: 1,394
Location: Xiamen China
Yes, that is possible. Please use the following code to add a binary content to a text content:

Code:

Cms_ContentFile contentFile = new Cms_ContentFile();
contentFile.TextContent = dataContext.QueryContent(textContentUUID).First();
contentFile.BinaryContent = dataContext.QueryContent(binaryContentUUID).First();
dataContext.AddToCms_ContentFile(contentFile);
dataContext.SaveChanges();


We have added that API in the coming version.
Regards,

Jifeng Huang

Kooboo Team

Microsoft ASP.NET MVP
salman
#19 Posted : Sunday, March 28, 2010 12:45:27 AM(UTC)
Rank: Member
Groups: Registered

Joined: 2/13/2010(UTC)
Posts: 20
Location: Rotterdam, Amsterdam, The Netherlands
Perfect! You guys rock!

Thnx!
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Powered by YAF 1.9.5.5 | YAF © 2003-2011, Yet Another Forum.NET
This page was generated in 0.119 seconds.