Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I want to create a WEB API that uploads a file from a given client onto a Azure. For this, I know I can use a class like: MultipartFormDataStreamProvider (not sure if this class works for Azure)

I want this API to be accessible from a variety of applications. For starters a simple .NET application. But my question is can I use this same API to handle file uploads from say an Android application, Windows 8 application, etc?

If this is not possible then do all these applications require a separate API exposed?

My idea of an API is that it can be used across a variety of applications for required functionality. But in this case the classes required to upload the file will restrict its usage.

share|improve this question

2 Answers 2

@nikhil pinto: The ASP.NET Web API helps you to create REST-Web service which can be consumed by any kind of client supporting HTTP request. I found this article here

http://hintdesk.com/android-upload-files-to-asp-net-web-api-service

very good because it illustrates how we can call the web service from different clients. Just check it out.

share|improve this answer

Web Api code to upload image

[System.Web.Http.AcceptVerbs("POST")]
        public async Task<object> AddAttachment()
        {
            if (!Request.Content.IsMimeMultipartContent("form-data"))
            {
                throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.UnsupportedMediaType));
            }

            NamedMultipartFormDataStreamProvider streamProvider = new NamedMultipartFormDataStreamProvider(
                HttpContext.Current.Server.MapPath("~/App_Data/"));

            await Request.Content.ReadAsMultipartAsync(streamProvider);
            string path = streamProvider.FileData.Select(entry => entry.LocalFileName).First();
            byte[] imgdata = System.IO.File.ReadAllBytes(path);

            return new
            {
                FileNames = streamProvider.FileData.Select(entry => entry.LocalFileName),

            };
        }
share|improve this answer
    
thanx for the code.But i already have this. I need to know whether this will work when i try to upload a file from say an Android App. –  nikhil pinto Feb 14 '14 at 10:47
    
i have not tried but i think it will work –  Nilesh Feb 14 '14 at 11:11

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.