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. Image for the cookie policy date

How to post to web api controller on another domain?

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

5 Replies

PO Prince Oliver Syncfusion Team September 20, 2017 05:23 AM UTC

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 




DE Dennis September 20, 2017 07:54 AM UTC

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


PO Prince Oliver Syncfusion Team September 21, 2017 09:05 AM UTC

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 



DE Dennis September 22, 2017 07:48 AM UTC

that did the trick, thank you.



PO Prince Oliver Syncfusion Team September 25, 2017 04:16 AM UTC

Hi Dennis,  

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

Regards, 
Prince 


Loader.
Live Chat Icon For mobile
Up arrow icon