0

I want to upload file with api, but also I need to send 'ID'. Same code is working in local, but does not working on IIS.

        [HttpPost("{id}")]
        [Route("Upload/{id}")]
        public async Task<IActionResult> Upload(int id)
        {
            using (var client = new HttpClient())
            {
                foreach (var file in Request.Form.Files)
                {
                    // . . . more logic    
                }
            }

            return new OkResult();
        }

In Local: enter image description here On IIS enter image description here

Raskolnikov
  • 3,791
  • 9
  • 43
  • 88
  • The Referer is different in case of IIS. Do you have a virtual Directory named dataset? – sachin Sep 14 '16 at 06:21
  • All other api-s on same page are working fine. Just this one has issue. – Raskolnikov Sep 14 '16 at 06:29
  • Please try setting the content type for the HttpClient's post content. Refer- http://stackoverflow.com/questions/27425043/upload-image-using-httpclient and http://stackoverflow.com/questions/16416601/c-sharp-httpclient-4-5-multipart-form-data-upload – Souvik Ghosh Sep 14 '16 at 06:42
  • in iis Adding MIME Types reffer this link for adding MIME type -[link](https://msdn.microsoft.com/en-us/library/bb742440.aspx) and show all MIMe type for all file reffer this link add mime type for zip file --[link](https://www.sitepoint.com/web-foundations/mime-types-complete-list/) – jayesh dhameliya Sep 14 '16 at 06:51
  • I found solution, it is very stupid. On client in angular I had "path url: '/api/transfer/upload/' + 8" instead of "url: 'api/transfer/upload/' + 8". JUST ONE SLASH and not working on IIS ! – Raskolnikov Sep 14 '16 at 07:13

1 Answers1

-1

I found solution, it is very stupid.

On client in TypeScript I had.

 this.$upload.upload({
                url: '/api/transfer/upload/' + this.id,
                method: 'POST',
                headers: { 'Content-Type': 'multipart/form-data' },
                file: file,
                fileName: file.name,
            })...

Instead of

 this.$upload.upload({
                url: 'api/transfer/upload/' + this.id,
                method: 'POST',
                headers: { 'Content-Type': 'multipart/form-data' },
                file: file,
                fileName: file.name,
            })

JUST ONE SLASH in url path and not working on IIS !

Raskolnikov
  • 3,791
  • 9
  • 43
  • 88