cancel
Showing results for 
Search instead for 
Did you mean: 

Document Type

albertogarcía
Champ in-the-making
Champ in-the-making
Hi,

Due to problems with versions I had to downgrade my Alfresco version to 3.1.2

I was using a newer version of the product to update custom type documents with this code

        PostMethod mPost = new PostMethod(urlString);
   Part[] parts = {
           new FilePart("filedata", filename, fileobj, filetype, null),
           new StringPart("filename", filename ),
           new StringPart("contenttype", "{bol.model}boletin" ),
           //modify this according to where you wanna put your content
      new StringPart("siteid", siteid),
      new StringPart("containerid", containeridbol)
      new StringPart("uploaddirectory", uploaddirectory)
      };
   mPost.setRequestEntity(new MultipartRequestEntity(parts, mPost.getParams()));
   int statusCode1 = client.executeMethod(mPost);

I have defined the model, and I can upload documents of the model manually, but when I execute the post method, ALfresco creates a document of defautl type like this:

Name: 40.pdf
Ref: workspace://SpacesStore/4ceab9c1-d0b6-45a3-8781-45bbe3a000a7
Type: {http://www.alfresco.org/model/content/1.0}content
DBID: 1.015.861

And should create a document like this instead

Name: aaaa.pdf
Ref: workspace://SpacesStore/6d33b3a6-8f4d-40fd-b0cf-1d800a4452e5
Type: {bol.model}boletin
DBID: 1.015.855

How can I do that with Alfresco 3.1.2? I can't find the property needed to upload a document of my type bol:boletin. I have added to the code some lines, but the only thing I can change is the contenttype

new StringPart("Type", "{bol.model}boletin" ),
new StringPart("type", "{bol.model}boletin" ),
new StringPart("contenttype", "{bol.model}boletin" )

CHANGE: {http://www.alfresco.org/model/content/1.0}contentType = {bol.model}boletin

Thanks in advance,
Alberto
15 REPLIES 15

kaynezhang
World-Class Innovator
World-Class Innovator
Please try with

Part[] parts = {
new FilePart("filedata", filename, fileobj, filetype, null),
new StringPart("filename", filename ),
new StringPart("contenttype", "{bol.model}boletin" ),
//modify this according to where you wanna put your content
new StringPart("siteid", siteid),
new StringPart("containerid", containeridbol)
new StringPart("uploaddirectory", uploaddirectory),
new StringPart("contentType", yourcontenttype)
};

Hi, Kaynezhang

Tried both ways (separatedly and with both instructions at the same time) before and after the siteid, containerid… but no way

new StringPart("contenttype", "{bol.model}boletin" ),
new StringPart("contentType", "{bol.model}boletin")

Any other idea?

Thanks

mrogers
Star Contributor
Star Contributor
what webscript are you using?

I am using the 3.1.2.17 Alfresco version and the following function: alfresco/service/api/upload?alf_ticket=

Thanks

kaynezhang
World-Class Innovator
World-Class Innovator
I have checked the code ,this parameter is case insensitive ,so "contenttype" and "contentType" both will work in version 4.2.
I don't have 3.1 enviroment,I don't have what is going on.
you can check "upload.post.js" file which locate in "${TOMCAT_ROOT}/webapps/alfresco/WEB-INF/classes/alfresco/templates/webscripts/org/alfresco/repository/upload" ,this file is upload webscript 's controller javascript,it will tell you correct parameter format.

mrogers
Star Contributor
Star Contributor
Should be contenttype although case does not matter.   And it should work in 3.1.

I wonder if your problem elsewhere?   In particular downgrade is likely to cause problems.

Thanks to both of you. I had checked the js function too, and seemed to me that the function call it was Ok.
I have 4 custom models, and it happens when I upload a document of any data. It happens in all of them.

The fact is that it does not work properly, and sets the contenttype into the properties but not in the Type (check the images I attach)

The downgrade is because of the client side. I have adapted a working 4.2 code to a new 3.1 environment (it is a fully new environment).

Could it be something that I have to change in Alfresco, some property, some configuration? Perhaps the value set is not correctly written for Alfresco 3.1 (instead of new StringPart("contenttype", "{visor.model}visor" ) or new StringPart("contenttype", "{bol.model}boletin" ) I have to write the type a different way)

If I write new StringPart("contenttype", "whatever I write here" )

The document is created and in the properties I get: {http://www.alfresco.org/model/content/1.0}contentType = whatever I write here

Thanks

I got the mistake. It is in the file upload.post.js

3.1 version
      var newFile = destNode.createFile(filename);
      newFile.properties.contentType = contentType;
      newFile.properties.content.write(content);

4.2 version
      if (contentType !== null)
         {
            newFile = destNode.createFile(filename, contentType);
         }
         else
         {
            newFile = destNode.createFile(filename);
         }


Can I change this directly there, is there any problem? is this method supported in 3.1? If I change it there, is something else needed

Changed for 3.1, but method not supported

Can't find method org.alfresco.repo.jscript.ScriptNode.createFile(java.lang.String,java.lang.String)

Any ideas?