cancel
Showing results for 
Search instead for 
Did you mean: 

webscript and .Net

buurd
Champ in-the-making
Champ in-the-making
Hi!

I'm trying to integrate a .Net-based (1.1) with an webscript. The webscript is basically a simple fileupload simular to the example on the wiki.

The problem I'm having is that I and my colleague can't seem to post the file from .Net (no html-page). My hope with writing here is that someone has done this and can point to a library that could take care of the plubing in .Net (HttpWebRequest) and simply make sure that the parameters get to Alfresco correcly. After nearly a day of googling and trying we havn't get any closer.

Thanks in advance
Roland
6 REPLIES 6

mikeh
Star Contributor
Star Contributor
Do you mean something like this..?

http://www.codeproject.com/KB/cs/multipart_request_C_.aspx
(you may need to register - free)

Thanks,
Mike

buurd
Champ in-the-making
Champ in-the-making
Hi!

I've got the following "traces" (witch of noone works, my script see no parameters):


POST /alfresco/service/jkptk/archive HTTP/1.1
Pragma: no-cache
Content-Type: multipart/form-data
Content-Length: 217
Host: rh:8080

–AaB03x
Content-Disposition: form-data; name="param1"

param1Value
–AaB03x
Content-Disposition: file; name="file"; filename="fileName1.txt"
Content-Type: text/plain

Content of fileName1.txt
–AaB03x


POST /alfresco/service/jkptk/archive HTTP/1.1
Content-Type: multipart/form-data
Content-Length: 35
Host: rh:8080

Name=Rick+Strahl&Company=West+Wind+

The script that is supposed to view the parameters:

var content = "";
var filename = "";
var objectId = "";
var documentClassName = "";
var versionDate = "";

logger.log("Started");
// locate file attributes
for each (field in formdata.fields)
{
  if (field.name == "objectId")
  {
    objectId = field.value;
    logger.log(field.name + ": " + field.value);
  }
  else if (field.name == "class")
  {
    documentClassName = field.value;
    logger.log(field.name + ": " + field.value);
  }
  else if (field.name == "versionDate")
  {
    versionDate = field.value;
    logger.log(field.name + ": " + field.value);
  }
  else if (field.name == "file" && field.isFile)
  {
   filename = field.filename;
    content = field.content;
    logger.log(field.name + ": " + field.filename);
  }else{
     logger.log(field.name + ": " + field.value);
  }
}

Any ideas why we don't se any parameters?

Thanks in advance
Roland

mikeh
Star Contributor
Star Contributor
I'm not sure why you're generating two POSTs - only the first one is valid multipart/form format.

Which version of Alfresco are you trying this on? Note that v2.1 Community doesn't have support for the formdata variable (http://wiki.alfresco.com/wiki/Web_Scripts#2:_Create_an_Execution_Script).

Here's a working trace from a file I just uploaded to the 3.0 Share client…
POST /share/proxy/alfresco/api/upload?alf_ticket=TICKET_91af0ebeebefdf1722b48624e48e55c8ea9c0b70 HTTP/1.1
Accept: text/*
Content-Type: multipart/form-data; boundary=———-Ij5gL6ei4GI3ae0KM7KM7GI3Ef1Ef1
User-Agent: Shockwave Flash
Host: mikemac01:8081
Content-Length: 1172
Connection: Keep-Alive
Pragma: no-cache
Cookie: alfLogin=1222853195; JSESSIONID=D86206D167F83B0DE3F0C96061155ADF

————Ij5gL6ei4GI3ae0KM7KM7GI3Ef1Ef1
Content-Disposition: form-data; name="Filename"

file1.txt
————Ij5gL6ei4GI3ae0KM7KM7GI3Ef1Ef1
Content-Disposition: form-data; name="thumbnails"

doclib
————Ij5gL6ei4GI3ae0KM7KM7GI3Ef1Ef1
Content-Disposition: form-data; name="containerId"

documentLibrary
————Ij5gL6ei4GI3ae0KM7KM7GI3Ef1Ef1
Content-Disposition: form-data; name="contentType"

Content
————Ij5gL6ei4GI3ae0KM7KM7GI3Ef1Ef1
Content-Disposition: form-data; name="siteId"

site1
————Ij5gL6ei4GI3ae0KM7KM7GI3Ef1Ef1
Content-Disposition: form-data; name="overwrite"

true
————Ij5gL6ei4GI3ae0KM7KM7GI3Ef1Ef1
Content-Disposition: form-data; name="username"

null
————Ij5gL6ei4GI3ae0KM7KM7GI3Ef1Ef1
Content-Disposition: form-data; name="uploadDirectory"

/
————Ij5gL6ei4GI3ae0KM7KM7GI3Ef1Ef1
Content-Disposition: form-data; name="filedata"; filename="file1.txt"
Content-Type: application/octet-stream

Contents of file1.txt
————Ij5gL6ei4GI3ae0KM7KM7GI3Ef1Ef1
Content-Disposition: form-data; name="Upload"

Submit Query
————Ij5gL6ei4GI3ae0KM7KM7GI3Ef1Ef1–

Note: you may also need to append the ticket to the URL as it looks as though .NET isn't forwarding any session information. My trace was from the Flash uploader, where this is a known limitation.

Thanks,
Mike

buurd
Champ in-the-making
Champ in-the-making
Hi Mike and thanks for the help!

Your "trace" gave us a couple of clues of what the most important probably should be posted as a bug (unless there are a strange rule in the http-protocol).

The problem was simply that Alfresco 2.2 Enterprise does not accept a file as the last parameter in the "body" of the request. When simply changing the order of the parameters my webscript began to see the parameters. Kind of strange. I'd hope that I can send two "traces" tomorrow when I'm back at the office to illustrate the problem.

Best Regards
Roland

mikeh
Star Contributor
Star Contributor
Could well be a bug then. If you're an Enterprise customer, please open a support ticket referencing this topic so we can prioritise any fixes needed. Your two traces will be very useful.

Thanks,
Mike

buurd
Champ in-the-making
Champ in-the-making
Hi!

It was not a bug in Alfresco but somewhere in out code after all. I was going to write the bugreport this weekend but could not reproduce it and since I was so sure about the bug I didn't save the bad traces. But nothing bad that don't come with something good. We now have a really nice class for posting in our .Net-codebase. Smiley Happy

Thanks for all help

Best regards
Roland