cancel
Showing results for 
Search instead for 
Did you mean: 

Cannot create content with CMIS webscript

edazcalf
Champ in-the-making
Champ in-the-making
Hi.
I cannot upload content to my Alfresco repository. CMIS webscripts have been useful for me to get content data, get content properties and list folder contents, but my problem comes when the request method is POST, which is necessary to upload content.

Inside my .NET code I have tried with the HttpWebRequest object, and I'm always getting this error message "(400) Bad Request". I suppossed I was sending incorrect data in the stream, or perhaps something was missing in the headers or content type… The fact is that I decided to use simple javascript code embedded into a little HTML page. The HTML is very similar to the one shown in the Alfresco wiki  (http://wiki.alfresco.com/wiki/Web_Scripts_Examples#File_Upload). The following is the only HTML I'm using to access the web script:

<html>
<head>
   <title>Upload Web Script Sample</title>
</head>
<body>
   <table>
     <tr>
       <td><nobr>Upload Web Script Sample</nobr></td>
     </tr>
   </table>
   <p>
   <table>
     <form action="http://localhost:8080/alfresco/service/api/path/Workspace/SpacesStore/Company%20Home/User%20Homes/te..." method="post" enctype="multipart/form-data" accept-charset="utf-8">
       <tr><td>File:<td><input type="file" name="ContentStream">
       <tr><td><td><input type="hidden" name="typeId" value = "Document">

       <tr><td><td><input type="submit" name="submit" value="Upload">
     </form>
   </table>
</body>
</html>

Note that I use the same method and enctype from the wiki example, but when I click on the "upload" button I'm asked to enter the user credentials (I use the admin user) then get the same error message "400 - Bad Request". What does this mean??? Is Internet Explorer (/Google Chrome/Mozilla Firefox) wrong at executing POST requests??? of course not !!! There is something missing at my client code or my Alfresco Server!  Smiley Sad

As you can see in my HTML the webscript Url I'm trying to access is :
http://localhost:8080/alfresco/service/api/path/Workspace/SpacesStore/Company%20Home/User%20Homes/te...
… which I expected to be enough to create "fivepm.txt" file inside my repository.

I send two parameters, as explained in the webscript description:

typeId: "Document"
ContentStream: (The uploaded text file)

What else is needed to upload files with Alfresco Web Scripts? I have a long time stuck on this subject.

Thanks a lot and have a nice day !!!
3 REPLIES 3

mrogers
Star Contributor
Star Contributor
What's a PUSH request.   Do you mean POST?

edazcalf
Champ in-the-making
Champ in-the-making
:$
Yes, a POST request. Sorry.

edazcalf
Champ in-the-making
Champ in-the-making
Well, my problem is solved.
After finding the script that was mapped to the Uri I was using (the one which was supposed to upload a file into repository using POST method) I could see clearly that it comes with no implementation. The script is located at
tomcat\webapps\alfresco\WEB-INF\classes\alfresco\templates\webscripts\org\alfresco\repository\store\children.post.js
… and it has no implementation, it says:   "// TODO: Handle direct posting of media" and finally returns a 400 (Bad request).

I'm using Alfresco Community v3.2.0 (r 2384). I tried this just because this service was listed in the web scripts index.

The good news for me was that the upload example in
http://wiki.alfresco.com/wiki/Web_Scripts_Examples#File_Upload
worked perfectly.