Problem downloading defect attachment content using REST API in ALM due to special characters in filename
Question ID: 108209
1
0

I am able to retrieve (all?/most) other attachments with no issue, but anything containing plus sign I cannot.

Specific example:

"Summary" : "ScriptX+DataYProblem Screens.doc",
"parent-id" : "21257",
"parent-type" : "defect",
"ref-type" : "File",

I need the REST API to retrieve the content of that attachment on the defect.

For any other attachment, I can request the url:

https://myALM.saas.hpe.com/qcbin/rest/domains/PRODUCTION_XYZCO/projects/ProjectXYZ
/defects/21257/attachments/${efname}?alt=application/octet-stream

Where efname is the URL-encoded filename, which in this case should be:

ScriptX%2BDataYProblemScreens.doc

End result though is that I get an error from the remote server and no content. For others, it works fine.

Marked as spam
Posted by (Questions: 36, Answers: 3)
Asked on March 20, 2018 7:52 pm
568 views
Answers (1)
0
Private answer

Danny,

This is a known issue with the REST API for which Micro Focus does have an existing Enhancement Request. For now, you could do something quick like renaming the problem attachments. Since identifying and renaming them manually would likely be a pain, you could implement some workflow code or OTA code to do the trick. Since it appears you are on a SaaS instance, I believe you or your admin should have access to the workflow customization for the Project. If I were in this situation, I would simply implement a toolbar button in the defects module that goes through the list of attachments on each defect, and then examines the name of each attachment, produce a clean filename if special characters are detected, then rename the attachment with that clean filename.

I have written some code to do just that. This code comes with no warranty, so use it at your own risk. Place it in the workflow for the project in question and it will rename the attachments for you. There are some message boxes that slow it down currently, but you could strip those out once you have vetted the code in a test project.

You will need to know a little about how to implement a toolbar button on the defect toolbar, I am not going to explain all that here. It is fairly straightforward in the workflow script editor. My workflow toolbar button is tied to an action called ''UserDefinedActions.Defects_Action1''. You'll see that in the code below. I simply have an if statement in the ActionCanExecute Function in the workflow that triggers my code to run. My code also calls another function called ''CleanString''. Just place it anywhere outside the other workflow functions. There are some comments, but be sure to try it in a test project first so that you are sure you know exactly what it is doing.

Function CleanString(strInput)
'create regular expression object
set re = new regexp
'set the pattern to match: characters that look like plus sign (U+002B)
'and some other examples like forward slashes (solidus [U+002F], fraction slash [U+2044], and division slash [U+2215])
' add any other characters identified as problematic here in the 're.Pattern' to clean them from the attachment filenames
' it is 'a pipe delimited list of characters to look for in the regex
re.Pattern = ''(u002B|u002F|u2044|u2215)''
re.IgnoreCase = True
'match all instances found
re.Global = True
' replace all found bad characters with an underscore
CleanString = re.Replace(strInput, ''_'')
'free memory
set re = nothing
End Function

Function ActionCanExecute(ActionName)

if ActionName=''UserDefinedActions.Defects_Action1'' Then
'msgbox ActionName
Dim attachFact
Dim theAttachment
Dim attachList
Dim BugFact
Dim tdc
Dim theBugList
Dim Actions
Dim Bug
Dim Attachment
Dim AttachmentFilter
Dim cleanFileName

Set tdc = TDConnection
Set BugFact = tdc.BugFactory
Set theBugList = BugFact.NewList('''')
For Each Bug In theBugList
Set attachFact = Bug.Attachments
Set attachList = attachFact.NewList('''')
For Each theAttachment In attachList
cleanFileName=CleanString(theAttachment.Name)
if StrComp(cleanFileName,theAttachment.Name,0) = 0 Then
msgbox ''Original Filename'' & vbCrLf & theAttachment.Name _
& vbCrLf & vbCrLf & ''New Clean FileName'' & vbCrLf & cleanFileName _
& vbCrLf & vbCrLf & ''MATCH, NO CHANGE NEEDED''
else
msgbox ''Original Filename'' & vbCrLf & theAttachment.Name _
& vbCrLf & vbCrLf & ''New Clean FileName'' & vbCrLf & cleanFileName _
& vbCrLf & vbCrLf &

Marked as spam
Posted by (Questions: 6, Answers: 167)
Answered on March 20, 2018 8:11 pm
0
Here is a helpful site to translate any other special characters to their Unicode character code as used in the code above. [https://unicode-table.com/en/#control-character][1] [1]: https://unicode-table.com/en/#control-character
( at March 20, 2018 8:22 pm)
EyeOnTesting

Welcome back to "EyeOnTesting" brought to you by Orasi Software, Inc.

X
Scroll to Top