CreateFileAttachment - file location Question

0
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.
Responses (10)
  • Accepted Answer

    Wednesday, August 21 2013, 04:30 AM - #Permalink
    0
    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...
    The reply is currently minimized Show
  • Accepted Answer

    Thursday, August 22 2013, 02:09 AM - #Permalink
    0
    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")
    The reply is currently minimized Show
  • Accepted Answer

    Thursday, August 22 2013, 12:49 PM - #Permalink
    0
    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.
    The reply is currently minimized Show
  • Accepted Answer

    Thursday, August 22 2013, 01:34 PM - #Permalink
    0
    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 ( :-) ).
    The reply is currently minimized Show
  • Accepted Answer

    Thursday, August 22 2013, 02:04 PM - #Permalink
    0
    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,
    The reply is currently minimized Show
  • Accepted Answer

    Thursday, August 22 2013, 07:39 PM - #Permalink
    0
    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
    The reply is currently minimized Show
  • Accepted Answer

    Wednesday, April 23 2014, 04:32 AM - #Permalink
    0
    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.
    The reply is currently minimized Show
  • Accepted Answer

    Wednesday, April 23 2014, 01:35 PM - #Permalink
    0
    Sorry Michael. We put this in the too hard basket.
    The reply is currently minimized Show
  • Accepted Answer

    Thursday, April 24 2014, 09:04 AM - #Permalink
    0
    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...
    The reply is currently minimized Show
  • Accepted Answer

    Friday, April 25 2014, 04:34 AM - #Permalink
    0
    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")
    The reply is currently minimized Show
Your Reply

Recent Tweets