Base solution for your next web application
Starts in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

where/how to save an uploaded document? #1100


User avatar
0
zokho created

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)
  • User Avatar
    0
    hikalkan created
    Support Team

    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.

  • User Avatar
    0
    zokho created

    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:

    1. 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?!
    2. 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!)
    3. 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... ;)