We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.

How to post to web api controller on another domain?

Thread ID:

Created:

Updated:

Platform:

Replies:

132753 Sep 19,2017 08:53 AM Sep 25,2017 12:16 AM ASP.NET Core 5
loading
Tags: UploadBox
Dennis
Asked On September 19, 2017 08:53 AM

I am using the uploadbox like this:

<ej-upload-box id="UploadDefault" save-url="SaveFiles" remove-url="RemoveFiles" extensions-allow=".txt,.csv" allow-drag-and-drop="true"
                       multiple-files-selection="true" drop-area-text="Drop files here" drop-area-height="300px">
        </ej-upload-box>

this posts to a normal controller within the same domain, but i want to post the files to a web api in another project, wich is essentialy another domain.
Can i use this control like this:

<ej-upload-box id="UploadDefault" save-url="http://localhost:5000/api/upload/SaveFiles" remove-url="http://localhost:5000/api/upload/RemoveFiles" extensions-allow=".txt,.csv" allow-drag-and-drop="true"
                       multiple-files-selection="true" drop-area-text="Drop files here" drop-area-height="300px">
        </ej-upload-box>

thanks,

Dennis

Prince Oliver [Syncfusion]
Replied On September 20, 2017 01:23 AM

Hi Dennis, 

Thank you for contacting Syncfusion forums. 

Yes, you can post the files to a WebApi service in another domain using the Uploadbox control. We have prepared a sample for your reference, please find the sample from the following link: http://www.syncfusion.com/downloads/support/directtrac/132753/ze/UploadboxCore-210038579 

Regards, 
Prince 



Dennis
Replied On September 20, 2017 03:54 AM

thank you for the response. the problem was in the fact that the api was asynchronis and i had to add:

async-upload="true"

i have included my test project, the problem i have now is that files list remain empty, what changes do i need to make to api controller


Attachment: UploadboxCore_c4bc63b6.zip

Prince Oliver [Syncfusion]
Replied On September 21, 2017 05:05 AM

Hi Dennis, 

Thank you for your update. 

In the API controller, you need to enable CORS (i.e) allow cross origin requests. You can configure CORS policy at application startup in the ConfigureServices method for the UploadboxCoreApi. Kindly refer to the following code snippet. 

[Startup.cs] 
public void ConfigureServices(IServiceCollection services) 
{ 
    // Add framework services. 
    services.AddMvc(); 
    services.AddCors(o => o.AddPolicy("MyPolicy", builder => 
    { 
        builder.AllowAnyOrigin() 
                .AllowAnyMethod() 
                .AllowAnyHeader(); 
    })); 
} 
 
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) 
{ 
    loggerFactory.AddConsole(Configuration.GetSection("Logging")); 
    loggerFactory.AddDebug(); 
    app.UseCors("MyPolicy"); // applying to every requests 
    app.UseMvc(); 
} 

We have modified the sample for your reference, please find the sample from the following link: http://www.syncfusion.com/downloads/support/forum/132753/ze/UploadboxCore-53233327 

Regards, 
Prince 


Dennis
Replied On September 22, 2017 03:48 AM

that did the trick, thank you.


Prince Oliver [Syncfusion]
Replied On September 25, 2017 12:16 AM

Hi Dennis,  

Most Welcome. We are glad that your issue is resolved. 

Regards, 
Prince 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;