ECL.WS help - postAttachment
Is there anything I'm missing here, or is there something special that needs to be done to get postAttachment to work using ECL.WS
//THIS WORKS
//ListResult list = eclWS.GetList(eclServiceSession, ListContentsType.Blank, new ListFilter(), "", "", 1, 100);
//Console.Write(list.Data);
//THIS DOESN’T WORK – WHY?
FileStream inputFile = File.OpenRead("C:\\");
BinaryReader reader = new BinaryReader(inputFile);
eclWS.PostAttachment(eclServiceSession, "",EclWSSvc.AttachmentOwnerType.Folder, "C:\\",reader.ReadBytes((int)(inputFile.Length)));
Comments
-
Try getting the byte array like this:
byte[] MyBytes = System.IO.File.ReadAllBytes(strAttachmentPath);
The 4th arg in PostAttachment() should only be the file name, not the entire path.
Also, I'm pretty sure PostAttachment() needs to be called within the context of a started action so the pseudo code would look like...
start action
post attachment
submit action
The attachment clip on the form would need the file name assigned to it in the form field collection you pass in as part of the SubmitAction(). This is no different than what you would be doing in the standard web client.
0 -
Thanks Tony
I'd already tried the filename and byte array suggestions with no change in results.
I have a multi-attachment clip on the form, and did try the start action + post attachment + submit action and received an error.
Since the actual form has a multi clip, it didnt have a field associated with it.
Do I have to create a dummy form with just a single attachment clip on it, to get this to work?
0 -
Changed it to a simple form with 1 attachment clip on it, and no other fields. Changed code as below, and now it errors on the first line of startAction . There might be some configuration gone wrong here
FormField[] asd = new FormField[] {
new PraxTest.EclWSSvc.TextField() { Name = "Attachment1", Value = "", Culture = CultureInfo.InvariantCulture.ToString() }
};PraxTest.EclWSSvc.ActionResponse response = eclWS.StartAction(eclServiceSession, "", "PraxTesterProcess", "UserAction1", false, asd);
eclWS.PostAttachment(eclServiceSession, "", EclWSSvc.AttachmentOwnerType.Folder, @"",
reader.ReadBytes((int)(inputFile.Length)));eclWS.SubmitAction(eclServiceSession, response.Action.FolderID, response.Action.Name, response.Action.FormName,
response.Action.ServerData, response.Action.Fields);0 -
Who are you logging in as? That user needs to be in a privy role for that action. What is the error?
Here is the entire winforms code for a single attachment clip:
private ServiceSessionState eclServiceSession = new ServiceSessionState(); private ServiceClient eclWS = new ServiceClient(); private void button1_Click(object sender, EventArgs e) { string strAttachmentName = "cat.jpg"; string strAttachmentPath = Application.StartupPath + System.IO.Path.DirectorySeparatorChar + strAttachmentName; try { FormField[] loginData = new FormField[] { new TextField() { Name = "username", Value = textBox1.Text.Trim(), Culture = CultureInfo.InvariantCulture.ToString() }, new TextField() { Name = "password", Value = PasswordEncrypt(textBox2.Text.Trim()), Culture = CultureInfo.InvariantCulture.ToString() } }; // Must pass in the appropriate index of the eUser.js for forms login eclServiceSession = eclWS.Login("WEB;", Convert.ToInt16(textBox3.Text.Trim()), "", loginData); if (eclWS.IsLoggedIn(eclServiceSession)) { // Start the action and work off of the returned object for the remainder of the request ActionResponse StartAR = eclWS.StartAction(eclServiceSession, "", "SimpleFormProc", "FirstAction", false, null); // Assign values to each FormField in the returned collection foreach (FormField ff in StartAR.Action.Fields) { switch (ff.Name.ToUpper()) { case "TXTNAMEFIRST": (ff as TextField).Value = "Tony"; break; case "TXTNAMELAST": (ff as TextField).Value = "W"; break; case "INTAGE": (ff as NumberField).Value = 100; break; case "DTANNIVERSARY": // Declare DateTime nullable DateTime? DummyDateTime = null; (ff as DateTimeField).Value = DummyDateTime; break; case "TXTATTACHMENT": (ff as ClipField).Value = strAttachmentName; break; default: break; } } byte[] attBytes = System.IO.File.ReadAllBytes(strAttachmentPath); // Post the attachment eclWS.PostAttachment(eclServiceSession, StartAR.Action.FolderID, AttachmentOwnerType.Folder, strAttachmentName, attBytes); // Submit the Action using objects returned from the original StartAction ActionResponse SubmitAR = eclWS.SubmitAction(eclServiceSession, StartAR.Action.FolderID, StartAR.Action.Name, StartAR.Action.FormName, StartAR.Action.ServerData, StartAR.Action.Fields); if (SubmitAR.ResponseType == ActionResponseType.Submit) { MessageBox.Show("Folder: " + SubmitAR.Submit.Id + " successfully submitted"); } else { MessageBox.Show("There was a problem while submitting Folder: " + SubmitAR.Submit.Id); } } else { MessageBox.Show("Cannot log you in."); } } catch (FaultException<OperationsFaultContract> ex) { for (int i = 0; i < ex.Detail.m_messages.Length; i++) { MessageBox.Show(ex.Detail.m_messages[i].ToString()); } } }
0 -
Thanks for the example!
Access definitely seems to be the issue here - although I'm not sure its the metastorm ToDo List access or some other webservice access.
The error throws a "PraxTest.EclWSSvc.ExceptionType.AccessDenied" - but when looking at eAlert entries for the folder in question, it has every user in the system - including eguest and Sysadmin.
Sysadmin is the login I used in my example, and the login itself succeeded - so not sure why its complaining about access now. Is there something else that needs to be done to gain access ?
0 -
The eAlert table only shows what folders are on users' lists, it doesn't show access to actions.
What role is associated with 'UserAction1'?
If its a static role make sure that the user calling StartAction has that role (check the admin tools or eAssignment table)
If its a dynamic role make sure that the formula is evaluating correctly to the user that is calling StartAction.
Also, you don't need an attachment clip on the form in order to post files to a folder using the ECL... you just need to be within a valid action.
iain
0 -
Awesome, thank you lain. That makes sense. I'll try that.
0
Categories
- All Categories
- 123 Developer Announcements
- 54 Articles
- 152 General Questions
- 148 Thrust Services
- 57 Developer Hackathon
- 37 Thrust Studio
- 20.6K Analytics
- 4.2K AppWorks
- 9K Extended ECM
- 918 Core Messaging
- 84 Digital Asset Management
- 9.4K Documentum
- 32 eDOCS
- 190 Exstream
- 39.8K TeamSite
- 1.7K Web Experience Management
- 9 XM Fax
- Follow Categories