Thanks Neil. I found another solution that was much more complicated, but still works pretty good. It ended up being very specific for my solution, so I cannot really post code unless i clean it up good and I haven't got the time right now. Your's looks nice and simple to work with.
Hi Neil,
I'm trying to replicate your code in my custom package, but it doesn't work.
I have a custom section with a custom tree. The first voice of the tree allows users to upload an image in my custom directory in "~/Media" directory on file system
Below you can find view, controller, resource and c# code.
Can you help me to understand where is the problem and how to solve it?
Were you able to put a breakpoint onto your method PostAFCLPUploadImage?
Does the code execute that far?
If not it could be a path problem where the Ajax is not hitting your method?
Although I would of thought that should return a 404 error if it can't find it.
Yeah, I put a breakpoint at the first line of the c# method but the code don't execute.
Yeah, there is a problem in Ajax but I don't understand where.
The info about the error, are very poor.
I tried to put a breakpoint in the resource code, It seems all ok but when the c# method must be called, the console (Client) display the "500 - Internal Server Error".
I tried also to call the method without send the file upload data and the c# method is executed correctly.
I already used a custom upload in frontend with a SurfaceController and ActionResult and it function properly, but now I need to do the same in my backoffice extension.
I tried to modify the code as below and finally I arrive on my POST method.
The problem now is that for some reason the request.FileData is empty (no file)
Uploading File/Image from Custom Dashboard form via AngularJs and UmbracoAuthorizedApiController
Hi
I'm using Umbraco 7.4.3
I have a custom dashboard with several new sections and tabs. I have some forms that ive set up and are hitting my API methods.
I have one form in particular where I need to upload the form with an image. A profile picture for instance. So the form consists of:
Profile Pic :
First Name :
There are more form elements but i've left them out for brevity.
I can pass all the textual form elements to my API method not a problem, but I need to pass the uploaded file. Preferably via HttpPostedFileBase.
Does anyone have any examples of passing an uploaded file to their controller.js and onto a UmbracoAuthorizedApiController HttpResponseMessage??
Did you solve this?
Hi Rune
Yeh I did in the end, not sure if is was the most elegant solution. Do you want me to post what I did?
I did this in case anyone else needs it in the HTML:
In my JS controller:
Then in my SurfaceController to get the HttpPostedFileBase I did this:
Like i say not sure if there is a more elegant way of doing this but it sure works Ok for me :)
Thanks Neil. I found another solution that was much more complicated, but still works pretty good. It ended up being very specific for my solution, so I cannot really post code unless i clean it up good and I haven't got the time right now. Your's looks nice and simple to work with.
/Rune
Hi Neil, I'm trying to replicate your code in my custom package, but it doesn't work.
I have a custom section with a custom tree. The first voice of the tree allows users to upload an image in my custom directory in "~/Media" directory on file system
Below you can find view, controller, resource and c# code.
Can you help me to understand where is the problem and how to solve it?
Thank you
Adriano
The View:
(No problem on rendering file upload fields)
The Controller:
(No problems on file selection)
The Resource
(Here I receive a "500 - Internal Server Error" after click the "upload" button. The action stops and don't reach c# code)
The C# method
Hi
Were you able to put a breakpoint onto your method PostAFCLPUploadImage?
Does the code execute that far?
If not it could be a path problem where the Ajax is not hitting your method? Although I would of thought that should return a 404 error if it can't find it.
Thank you for your quick answer.
Yeah, I put a breakpoint at the first line of the c# method but the code don't execute.
Yeah, there is a problem in Ajax but I don't understand where. The info about the error, are very poor.
I tried to put a breakpoint in the resource code, It seems all ok but when the c# method must be called, the console (Client) display the "500 - Internal Server Error".
I tried also to call the method without send the file upload data and the c# method is executed correctly.
I can only think it's maybe down to the routing in Umbraco? In my version i'm using a SurfaceController and an ActionResult type of Method.
Maybe try creating one in a SurfaceController of type ActionResult and see if it hits that with the HttpPostedFileBase
I already used a custom upload in frontend with a SurfaceController and ActionResult and it function properly, but now I need to do the same in my backoffice extension.
But unfortunately it doesn't work. :-(
That's really Odd.
I've created a custom dashboard and within one of the views im using this method and it hits my code Ok.
Could you maybe try just passing one parameter - allFiles and see if it hits it Ok then?
Now the error is :
This is the content of "allFiles"
Hi Neil, watching the header, when start upload, I found this exception message:
No MediaTypeFormatter is available to read an object of type 'HttpPostedFile' with media type "multipart/form-data"
Any Idea? :-o
I tried to modify the code as below and finally I arrive on my POST method. The problem now is that for some reason the request.FileData is empty (no file)
The View:
The Controller:
The Resource
The C# method
Hi Adriano
Did you resolve this problem? I also get FileData is empty
Hi Anton, wow...It's been a long time since the last post.
OK, I remember...I couldn't solve it so i decided to use a javascript uploader (kartikBootstrapUploader)
This solved my problem.
if you want I can give you the code.
Adriano
Thanks for getting back to me.
All good.
Seemed like a nice solution to upload multiple files
is working on a reply...