Alfresco repository Community 5.0d Upload REST API

Hello

I want to make a integration with my .NET Aplication with a Alfresco Upload API REST. I found this thread on the Alfresco community, with code java example. but i try to do with RESTSharp and dont any have success
https://forums.alfresco.com/forum/developer-discussions/alfresco-api/uploading-files-using-restful-10182013-1327

Someone can help me...in alfresco community doesnt have a .NET example to guide me :(  

Thanks in advance and sorry my english !!

here my code :
 string ticket = null;

                // Auth work OK
                var client = new RestClient("http://10.17.94.172:8080/alfresco/service/api/");
                client.Authenticator = new SimpleAuthenticator("u", "admin", "pw", "admin");

                var request = new RestRequest("login", Method.GET);
                IRestResponse response = client.Execute(request);
                if (response.StatusCode == HttpStatusCode.OK)
                {
                    XmlDocument doc = new XmlDocument();
                    doc.LoadXml(response.Content);
                    XmlNodeList elemList = doc.GetElementsByTagName("ticket");
                    for (int i = 0; i < elemList.Count; i++)
                    {
                        ticket = elemList[i].InnerText;
                    }
                    
                    
                    // list all files and folders work OK

                    client = new RestClient("http://10.17.94.172:8080/alfresco/service/slingshot/doclib/doclist/%7Btype%7D/site/fcvs/");
                    request = new RestRequest("documentlibrary?alf_ticket=" + ticket, Method.GET);
                    request.RequestFormat = DataFormat.Json;
                    response = client.Execute(request);
                    
                    ////created folder work OK
                    //client = new RestClient("http://10.17.94.172:8080/alfresco/service/api/site/folder/fcvs/");
                    //request = new RestRequest("documentlibrary?alf_ticket=" + ticket, Method.POST);
                    //request.RequestFormat = DataFormat.Json;                   
                    //Dictionary<string, string> entry = new Dictionary<string,string>();
                    //entry.Add("name", "Pushkin");
                    //entry.Add("type", "cm:folder");
                    //request.AddJsonBody(entry);
                    //response = client.Execute(request);

//Send a file to a folders (documentlibrary/folderX) that have create above
                    string path = @"C:\test.pdf";                

                    // Do it with RestSharp    doesnt work (404 ou 500 error) like a error "dont find the directory to upload"              

                    client = new RestClient("http://10.17.94.172:8080/alfresco/service/api/");
                    request = new RestRequest("upload?alf_ticket=" + ticket, Method.POST);
                    request.AlwaysMultipartFormData = true;
                    request.AddHeader("Content-Type", "multipart/form-data");
                    request.AddFile("filedata", System.IO.File.ReadAllBytes(path), Path.GetFileName(path));
                    request.AddParameter("filename", "test.pdf");
                    request.AddParameter("description", "arquivo Teste");
                    request.AddParameter("contenttype ", "application/pdf");
                    request.AddParameter("siteid" , "fcvs");
                    request.AddParameter("containerid", "Company Home");
                    request.AddParameter("destination ", "workspace://SpacesStore/3362a127-9f48-400c-87ce-c15ffd3a5964");
                   // request.AddParameter("uploaddirectory", "documentLibrary");
                    request.AddParameter("overwrite", true);
                   
                    response = client.Execute(request);

Open in new window

Igor NesrallaProprietárioAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

gurpsbassiCommented:
dont any have success

What do you mean ?
Can you supply the error message?
Igor NesrallaProprietárioAuthor Commented:
gurpsbassi,

sorry :)

i'v implement this code i received 404 or 500 http error:

When i received http 500 error is when i comment this line:
"// request.AddParameter("uploaddirectory", "documentLibrary");"
the return error is in attach file -> 500Error.txt.

And when i received http 404 error is when i uncomment this line  
"request.AddParameter("uploaddirectory", "documentLibrary");"
the return error is in attach file -> 404Error.txt.

I think is my problem is the way i'm doing the restful request...i realy dont know !


//Send a file to a folders (documentlibrary/folderX) that have create above
                    string path = @"C:\test.pdf";                

                    // Do it with RestSharp    doesnt work (404 ou 500 error) like a error "dont find the directory to upload"              

                    client = new RestClient("http://10.17.94.172:8080/alfresco/service/api/");
                    request = new RestRequest("upload?alf_ticket=" + ticket, Method.POST);
                    request.AlwaysMultipartFormData = true;
                    request.AddHeader("Content-Type", "multipart/form-data");
                    request.AddFile("filedata", System.IO.File.ReadAllBytes(path), Path.GetFileName(path));
                    request.AddParameter("filename", "test.pdf");
                    request.AddParameter("description", "arquivo Teste");
                    request.AddParameter("contenttype ", "application/pdf");
                    request.AddParameter("siteid" , "fcvs");
                    request.AddParameter("containerid", "Company Home");
                    request.AddParameter("destination ", "workspace://SpacesStore/3362a127-9f48-400c-87ce-c15ffd3a5964");
                   // request.AddParameter("uploaddirectory", "documentLibrary");
                    request.AddParameter("overwrite", true);
                   
                    response = client.Execute(request);

Open in new window

404Error
500Error
gurpsbassiCommented:
you are using :
 RestRequest("upload?alf_ticket=" + ticket, Method.POST);

and yet you are passing your data in as query params like a GET request.

You need to post a body when using POST.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.