2

I have an ASP.net application that allows the users to report bugs and attach files. The bug together with its detail and attachments should be saved in FogBugz. I have managed to create everything except the file attachment part.

here is my code:

private void NewCaseWithFile()

    {
        string fbUrl = "https://test.fogbugz.com/api.asp";
        string fbToken = logInFogBugz();
        string param = "";


        param += "cmd=new";
        param += "&token=" + fbToken;


        param += "&sTags=" + "OnlineService,";
        param += "&sTitle=" + "Testing";

        param += "&sEvent=" + "This case is being created from Visual Studio";
        param += "&nFileCount=" + "1";
        param += "&File1=" + "Picture.png";


        HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(fbUrl + "?" + param);
        httpWebRequest.Method = WebRequestMethods.Http.Post;
        httpWebRequest.ContentType = "multipart/form-data";

        httpWebRequest.Accept = "application/xml";
        httpWebRequest.ContentLength = 0;

        HttpWebResponse response = (HttpWebResponse)httpWebRequest.GetResponse();
        StreamReader streamReader = new StreamReader(response.GetResponseStream());
        XDocument doc = XDocument.Load(streamReader);
    }

I have tried all instructions under "Editing Cases" but it did not help. In fact I have no idea what are File 1, File 2 and how to send them to FogBugz.

Can anyone help me with this? Many thanks!

Haleh
  • 21
  • 3

1 Answers1

0

File1 should be specified in the body of your multipart/form-data post (not as a querystring parameter).

You actually have to specify all the bytes in the file.

There's an answer on fogbugz.stackexchange.com as well as a C# FogBugz API wrapper that will handle all the parts for you.

The form parts in the body of your post would look like

--sdfjdsjsdflk SOME BOUNDARY--
Content-Disposition: form-data; name="File1"; filename="foo.jpg"
Content-Transfer-Encoding: base64
Content-Type: image/png

slfkajdflksjflajfdj
sldfjsd;aljfds
these are actual data bytes from the foo.jpg file
slfkjdsfljds
sdflajsdfs

Or you can look at this question which points to an RFC with an example.

Community
  • 1
  • 1
Michael Pryor
  • 25,046
  • 18
  • 72
  • 90
  • While your link and sample is good and useful, your post seems a bit off. – Soeren L. Nielsen Oct 07 '13 at 18:22
  • Crappy comments system ;-) While your link and sample is good and useful, your post seems a bit off. Your form post specifies "base64" encoding; then you should also use it below. In this case the data would be: c2xma2FqZGZsa3NqZmxhamZkag0Kc2xkZmpzZDthbGpmZHMNCnRoZXNlIGFyZSBhY3R1YWwgZGF0YSBieXRlcyBmcm9tIHRoZSBmb28uanBnIGZpbGUNCnNsZmtqZHNmbGpkcw0Kc2RmbGFqc2Rmcw== That said I'm having problems with FogBugz ignoring the base64 flag and treating everything as binary. May be my bad ;-) – Soeren L. Nielsen Oct 07 '13 at 18:29