cancel
Showing results for 
Search instead for 
Did you mean: 

StatusCode 404(Not Found) on File Upload using Alfresco ReST api

jeevitha_balu
Champ in-the-making
Champ in-the-making
Hi,

I'm trying to upload a file to alfresco repository using ReST api. It succeeds on using POSTMAN Rest Client but somehow fails with Error 404 (Not Found) with the following code.

Could someone please let me know what am I doing wrong?

.Net Snippet:
            string folderURL = @"http://localhost:8080/alfresco/service/api/upload?alf_ticket=(ticket# goes here)";
            string filedata = @"C:\Test\TestJeevitha2.pdf";
           
            Stream fileStream = new FileStream(filedata, FileMode.Open, FileAccess.Read);
            HttpContent fileContent = new StreamContent(fileStream);
            HttpContent destinationContent = new StringContent("workspace://SpacesStore/7f4fee0e-ea6c-4606-8626-346f63a78790");
            HttpContent decsContent = new StringContent("a test upload");

            var client = new HttpClient();
            var formData = new MultipartFormDataContent();
           
                formData.Add(fileContent);
                formData.Add(destinationContent);
                formData.Add(decsContent);
                var response = client.PostAsync(folderURL, formData).Result;
               
                Label1.Text = response.StatusCode.ToString(); // The status code is 404.Not Found
                return response.Content.ReadAsStreamAsync().Result;
           
I have been breaking my head on what went wrong for the past one day tried several methods to pass parameters to post. Note: It works in POSTMAN perfectly and able to get the JSON response back.Can someone help?

Thanks in advance.
Jeevitha
2 REPLIES 2

koopa
Confirmed Champ
Confirmed Champ
Try using the method suggested <a href="http://stackoverflow.com/a/23824768/2519150">here on stackoverflow</a>

kaynezhang
World-Class Innovator
World-Class Innovator
You should alos specify parameters such as: filename、destination、uploaddirectory、siteid、containerid,so you should also add some code like following

      var values = new[]
        {
            new KeyValuePair<string, string>("filename", "filename"),
            new KeyValuePair<string, string>("description", "description"),
       new KeyValuePair<string, string>("destination", "workspace://SpacesStore/ce55a850-b1c7-43c7-a600-b5c58a985429"),
       new KeyValuePair<string, string>("siteid", "testsite"),
       new KeyValuePair<string, string>("containerid", "documentLibrary"),
        };

        foreach (var keyValuePair in values)
        {
            formData.Add(new StringContent(keyValuePair.Value), keyValuePair.Key);
        }


By the way ,why not use DotCmis client?