Lieutenant Commander
Lieutenant Commander
1659 views

ALM REST upload attachment - internal server error (500)

hi there,

i try to upload an attachment to a defect.

I always get an error internal server error (500).

This is the request stream i send, and for me it looks ok.

Has anyone an idea what might be the problem?

c# code

            string boundary = "uploadboundary";
            string URL = "http://server/qcbin/rest/domains/DOMAIN/projects/PROJECT/attachments";
            HttpWebRequest attRequest = (HttpWebRequest)WebRequest.Create(URL);
            
             attRequest.Method = "POST";
             attRequest.ContentType = "multipart/form-data; boundary=" + boundary;
             attRequest.Accept = "application/json";
            attRequest.CookieContainer = authRequest.CookieContainer;

            string FilePath = "test.txt";

            formData.Clear();
            formData["entity.type"] = "defect";
            formData["entity.id"] = "825";
            formData["filename"] = "test.txt";
            formData["description"] = "Testanhang";
             
            Stream postDataStream = GetPostStream(FilePath, formData, boundary);
            
            attRequest.ContentLength = postDataStream.Length;
            
            Stream reqStream = attRequest.GetRequestStream();

            postDataStream.CopyTo(reqStream);
            
            postDataStream.Close();
            reqStream.Close();
            
            
            HttpWebResponse attResponse = (HttpWebResponse)attRequest.GetResponse();

reqstream:


--uploadboundary
Content-Disposition: form-data; name="entity.type";

defect
--uploadboundary
Content-Disposition: form-data; name="entity.id";

825
--uploadboundary
Content-Disposition: form-data; name="filename";

test.txt
--uploadboundary
Content-Disposition: form-data; name="description";

Testanhang
--uploadboundary
Content-Disposition: form-data; name="file"; filename="test.txt"
Content-Type: text/plain

das ist ein test
--uploadboundary--

 

Tags (1)
0 Likes
4 Replies
Micro Focus Expert
Micro Focus Expert

Hi

Attachments are not part of the public API as stated in the documentation here: http://octane-help.saas.hpe.com/en/12.55.3/API/Developer_Help.htm#API/Attachments.htm

That means that you need to send a special header in order for the attachments to work.

If you are still having issues after adding the header please let me know

Spencer

0 Likes
Micro Focus Expert
Micro Focus Expert

Hi,

Could we perhaps send e.g. error 403 with an explanation instead?

Thanks,

Dirk

0 Likes
Micro Focus Expert
Micro Focus Expert

This is a possibility - however it does depend on what actually happened.  We would have to see further details about what exactly the problem is in this case

Spencer

0 Likes
Lieutenant Commander
Lieutenant Commander

Hi Spencer,

thank you for the info. No clue how to find it. In the offical rest api documentation is another description.

Anyway, I still have the same error. Hopefully cou can help me again.

KR

Bernd

POST /qcbin/rest/domains/CUSTOMER/projects/PROJECT/attachments HTTP/1.1

Content-Type: multipart/form-data; boundary=--uploadboundary

Accept: application/json

HPCLIENTTYPE: HPE_REST_API_TECH_PREVIEW

Host: msapp02p:8080

Cookie: LWSSO_COOKIE_KEY=IpX30bApPSUEUnP4Uq9IwSNbcdI89VgnNg5ISV3amF-1F2lqplnJblqtcrGOiM19JZrsJtZmtkFXpVVYKay9B-MEipAUhWaS7BOzjnj2ZlMe3ZHHZBCeSVY9Sbv-Bi8mfGUSkKp-mipMVsqbxt0tmf0kDvr3Hc7D707YUPwEnNVQLG4OgM714VtWyRVRDwzuqg0m6qWk1uHosNetQYd9QoWsasbUoPzq4cSm-iUnNPQR3mF7HyVf5HXULHJR89DaMqG42K6J7tCMZZjdOCcFNisBJNLSqHYckdJL-dV7k5s.; QCSession=NjMyOTc3O0prRVRIdWRUb2JTdmpacE8xN1dzRVEqKjtSRVNUIGNsaWVudDsgOyA.; ALM_USER=72cbc27efa8f4f748a37d85b07d99f9a31ec7e677ae6f4e1cec9425451e63a21; XSRF-TOKEN=3e9858df8e7be714dbda3127dafb7b26eaa71fbe364fe74ede0737a21a0358a4

Content-Length: 398

Expect: 100-continue

 

--uploadboundary

Content-Disposition: form-data; name="entity"

Content-Type: application/json; charset=UTF-8

{"owner_defect":{"id":846, "type":"defect"}, "name":"test.txt", "description":"Testanhang"}

--uploadboundary

Content-Disposition: form-data; name="content"; filename="test.txt"

Content-Type: text/plain

Content-Transfer-Encoding: base64

 

ZGFzIGlzdCBlaW4gdGVzdA==

--uploadboundary--

HTTP/1.1 500 Server Error

Date: Tue, 29 Aug 2017 14:38:56 GMT

X-Content-Type-Options: nosniff

Set-Cookie: LWSSO_COOKIE_KEY=Aaip8XXCQVxA3y8H5xAMp6Qq_qZPK1AW4Ga-QA6E_Ga2xFfdz-XuxgAKVz1gX0nUN1nlEbZbk0DN55G5BclxrmLkzJQT3spyI7Yd90cqpDDsPUFWMfU1r0h7GEf4AtIwaX7p-X26oRw5gDCugM3sau3HOwFNTh8IaZYdTI8mF0VpU4Jm0gHWnO3fQKVByBz7uw3eFWnqpEsV48Uagt01hhtV_u1jZp4DcwwaHyuP_PXwEGU4qi82-v2XG9a4OmluqCjLSFCKl2zCRhW9-1QES8kgXqopOgpb9U1E9FDFfBQ.;Path=/;HTTPOnly

Set-Cookie: JSESSIONID=2z8qhiduso8x1afvtp8zaw4ep;Path=/qcbin;HttpOnly

Expires: Thu, 01 Jan 1970 00:00:00 GMT

Content-Type: application/json

X-XSS-protection: 1; mode=block

Content-Length: 114

Server: Jetty(9.1.4.v20140401)

 

{"Id":"qccore.general-error","Title":"String index out of range: -1","ExceptionProperties":null,"StackTrace":null}

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.