Welcome Serena Central users! CLICK HERE
The migration of the Serena Central community is currently underway. Be sure to read THIS MESSAGE to get your new login set up to access your account.
dsheaffe Outstanding Contributor.
Outstanding Contributor.
12475 views

CreateFileAttachment - file location


I am just starting to play with the CreateFileAttachment web service, but something has me stumped.

Where do you define where the file is that you want uploaded as an attachment. eg, if I have a file sitting on my PC that I want to add as an attachment, how do I tell the web service where it is located.

I have found other posts on this site that might help - but they all have links to the "old" community site and they no longer work.
0 Likes
10 Replies
Highlighted
bamos Absent Member.
Absent Member.

Re: CreateFileAttachment - file location


David,

Unfortunately that web service isn't quite as simple as pointing to a file and uploading it. Take a look at the Web Service guide and it goes into more detail but basically the file has to be in Base64 encoded format so it would look something like this.

c2FtcGxlIGZpbGUgYXR0YWNobWVudA==

The bigger question would be how to get a file into that format which hopefully someone else in the community can help answer.

I know there are sites like this that will do it but not sure how you would do it on the fly when a user picks a file for instance.

http://www.motobit.com/util/base64-de.
0 Likes
doru_voinea Absent Member.
Absent Member.

Re: CreateFileAttachment - file location


Below is an POC in Python



import base64

import os

from suds.client import Client

SBM_USERNAME = "username"

SBM_PASSWORD = "passowrd"

SBM_WSDL = "http://sbm_server/gsoap/sbmappservices72.wsdl"

SBM_ENDPOINT = "http://sbm_server/gsoap/gsoap_ssl.dll?sbmappservices72"

def add_file(issueid, name, file_location):

client = Client(url=SBM_WSDL, location=SBM_ENDPOINT)

auth = client.factory.create('ns1:Auth')

table = client.factory.create('ns1:TableIdentifier')

table.dbName = "TTT_ISSUES"

where = "TS_ISSUEID = '%s'" % (issueid,)

answer = client.service.GetItemsByQuery(auth, table, where)

if answer.totalCount == 1:

item = items[0]

item_id = item.id

if os.path.exists(file_location):

attachment = client.factory.create('ns1:FileAttachmentContents')

attachment.name = name

attachment.fileName = os.path.split(file_location)[-1]

attachment.showAsImage = False

content = client.factory.create('ns1:FileBufferBase64')

content.data = base64.b64encode(open(file_location, 'rb').read())

attachment.contentsBase64 = content

if item and item.id.id > 0:

client.service.CreateFileAttachment(auth, item_id, attachment)

print "File %s added to %s" % (name, issueid)

else:

print "Error adding file"

if __name__ == "__main__":

add_file("400001", "My File", "d:/log.txt")


0 Likes
dsheaffe Outstanding Contributor.
Outstanding Contributor.

Re: CreateFileAttachment - file location


Thanks Brian & Doru. I think that I might leave this for the moment and get back to something simpler (like open heart surgery).

I have a developer in-house that wants to use some of the web services to make his life simpler (like creating primary items and querying), so I might put this on his to-do list for down the track.
0 Likes
pmthompson1954 Absent Member.
Absent Member.

Re: CreateFileAttachment - file location


From that information what I hear is that the answer is:



Create Primary Items

Query (ie reports)



I have to ask "What do you really want to do?". My experience is that SBM developers (myself included on occasion) too frequently fall into the "I need a script that will ...." trap without asking what the client or user really wants to do. Sometimes a workflow change or better end-user education is all that's needed.

Also, "use web services" and "make life simpler" could be an oxymoron ( 🙂 ).
0 Likes
dsheaffe Outstanding Contributor.
Outstanding Contributor.

Re: CreateFileAttachment - file location


Hi Paul,

What we really want to do is enhance the integration between SBM and other systems. We currently have clients who use the web services to create new primary items directly from their own defect tracking systems (eg, JIRA) - without the need to actually log into SBM and enter the same information again.

Now we wanted to extend that so that they could also add file attachments to SBM issues that they had previously submitted.

You are completely correct that it would probably be simpler if the client just logged in and added the attachments manually - but if we could provide them a value added service of having them post the same attachment from their issue system to ours it would be simpler for them (but not us).

Thanks,
0 Likes
doru_voinea Absent Member.
Absent Member.

Re: CreateFileAttachment - file location


David,

I think the best option will be as Serena to put in place some wrappers around the SBM SOAP API for common languages (Java, C#, dynamic languages) to overcome the complexity of SBM SOAP specs. This approach may increase also the traction for developer community
0 Likes
michaelmcole Absent Member.
Absent Member.

Re: CreateFileAttachment - file location


David, Did you manage to find a solution to this? I am also trying to figure out how to automate adding a log file to an SCR.
0 Likes
dsheaffe Outstanding Contributor.
Outstanding Contributor.

Re: CreateFileAttachment - file location


Sorry Michael. We put this in the too hard basket.
0 Likes
michaelmcole Absent Member.
Absent Member.

Re: CreateFileAttachment - file location


Trying to run this gives me an error:Traceback (most recent call last): File "attach.py", line 41, in <module> add_file("400001", "TEST file", "./testfile.txt") File "attach.py", line 13, in add_file auth = client.factory.create('ns1:Auth') File "build/bdist.solaris-2.10-i86pc/egg/suds/client.py", line 232, in create File "build/bdist.solaris-2.10-i86pc/egg/suds/resolver.py", line 107, in find File "build/bdist.solaris-2.10-i86pc/egg/suds/resolver.py", line 129, in root File "build/bdist.solaris-2.10-i86pc/egg/suds/resolver.py", line 194, in qualify File "build/bdist.solaris-2.10-i86pc/egg/suds/xsd/__init__.py", line 56, in qualifyException: prefix (ns1) not resolvedI am new to this so not sure what the problem is...
0 Likes
michaelmcole Absent Member.
Absent Member.

Re: CreateFileAttachment - file location


Managed to resolve my namespace issue, but still getting an error;Traceback (most recent call last): File "attach.py", line 41, in <module> add_file("232425", "TEST file", "./testfile.txt") File "attach.py", line 19, in add_file answer = client.service.GetItemsByQuery(auth, table, where) File "build/bdist.solaris-2.10-i86pc/egg/suds/client.py", line 542, in __call__ File "build/bdist.solaris-2.10-i86pc/egg/suds/client.py", line 602, in invoke File "build/bdist.solaris-2.10-i86pc/egg/suds/client.py", line 643, in send File "build/bdist.solaris-2.10-i86pc/egg/suds/client.py", line 678, in succeeded File "build/bdist.solaris-2.10-i86pc/egg/suds/bindings/binding.py", line 151, in get_reply File "build/bdist.solaris-2.10-i86pc/egg/suds/bindings/binding.py", line 182, in detect_faultsuds.WebFault: Server raised fault: 'Invalid table id 0.using the below code;def add_file(issueid, name, file_location): client = Client(url=SBM_WSDL, location=SBM_ENDPOINT) auth = client.factory.create('ae:Auth') auth.userId = SBM_USERNAME auth.password = SBM_PASSWORD table = client.factory.create('ae:TableIdentifier') table.dbName = "TTT_ISSUES" where = "TS_ISSUEID = '%s'" % (issueid,) answer = client.service.GetItemsByQuery(auth, table, where) if answer.totalCount == 1: item = items[0] item_id = item.id if os.path.exists(file_location): attachment = client.factory.create('ae:FileAttachmentContents') attachment.name = name attachment.fileName = os.path.split(file_location)[-1] attachment.showAsImage = False content = client.factory.create('ae:FileBufferBase64') content.data = base64.b64encode(open(file_location, 'rb').read()) attachment.contentsBase64 = content if item and item.id.id > 0: client.service.CreateFileAttachment(auth, item_id, attachment) print "File %s added to %s" % (name, issueid) sys.exit(0) else: print "Error adding file" sys.exit(1)if __name__ == "__main__": add_file("232425", "TEST file", "./testfile.txt")
0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.