Hi, I have created an uploading WebApi in the WebApi project. I am using the Api from the Web project to upload files via AngularJS. I have also created a directory and named it as "Document". Here are my wonders:
Where should I define the Document folder (in the WebApi project or the Web one)? I assume it should be in the Web project where the client-side code resides. If my guess is true, then do not know how to point to a folder in the Web project from the WebApi project to save the file in?!
Thanks for your tips and advice in advance ... ;)
2 Answer(s)
-
0
Folders should be in web project, yes. Web project can get absolute path using
HttpContext.Current.Server.MapPath("~/Documents");
You can use this code to set path to a static property defined in application project. Then you can use this property whenever you need.
I suggest to use dependency injection (create a class, register to DI, resolve it in web module's postinitialize and set folder paths. then inject it anywhere you need) instead of statics but both works.
-
0
Hi Ibrahim, Thanks again for your advice. Now I have got another question: I am using [https://github.com/danialfarid/ng-file-upload]) to upload files via Angular. I am using the code below to send userId as a form data multipart along with the uploaded file to create a folder as per its value and then save the uploaded file:
file.upload = Upload.upload({ url: '/api/File/Upload', data: {userId: appSession.user.id, file: file} });
For the whole past day I have been struggling to fetch the form-data and get the posted userId so I could create a folder prior saving the file. Do you have any advice on:
- Am I doing the right thing? I mean, do I really need to pass the userId along with the file or I could retrieve it in the WebApi project side somehow?!
- I have just come across this parser [https://github.com/Vodurden/Http-Multipart-Data-Parser]) which would let to parse the form-data request (have not tried that though as yet!)
- Is there a such parser within the ABP Framework so I could use rather using the above parser?
I really appreciate your advice and thanks in advance... ;)