如何更改httppostedfilebase的内容类型? [英] How to change the content type of httppostedfilebase?

查看:60
本文介绍了如何更改httppostedfilebase的内容类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用HttpPostedFileBase使用ASP.NET MVC上传文件。我需要将此发布到API调用,我收到错误StatusCode:403,Reason Phrase:'Forbidden',Version:1.1,Content:System.Net.Http.StreamContent。这是因为我将文件内容作为application / octet-stream传递,其中API调用希望内容类型为application / vnd.qlik.sense.app。互联网上的很多帖子都说HttpPostedFileBase是只读的,我们无法更改内容类型。任何人都可以告诉我们如何更改HttpPostedFileBase的内容类型。这可能吗?



我尝试过:



我我正在使用HttpPostedFileBase使用ASP.NET MVC上传文件。我需要将此发布到API调用,我收到错误StatusCode:403,Reason Phrase:'Forbidden',Version:1.1,Content:System.Net.Http.StreamContent。这是因为我将文件内容作为application / octet-stream传递,其中API调用希望内容类型为application / vnd.qlik.sense.app。互联网上的很多帖子都说HttpPostedFileBase是只读的,我们无法更改内容类型。

I am using HttpPostedFileBase to upload a file using ASP.NET MVC. I need to post this to a API call and i am getting a error "StatusCode: 403, Reason Phrase: 'Forbidden', Version: 1.1, Content: System.Net.Http.StreamContent". This is because i am passing file content as "application/octet-stream", where as API call wants the content type as "application/vnd.qlik.sense.app". Many posts in internet says that HttpPostedFileBase is a read only and we cannot change the content type. Can anybody let me know how we can change the content type of HttpPostedFileBase. Is this possible??

What I have tried:

I am using HttpPostedFileBase to upload a file using ASP.NET MVC. I need to post this to a API call and i am getting a error "StatusCode: 403, Reason Phrase: 'Forbidden', Version: 1.1, Content: System.Net.Http.StreamContent". This is because i am passing file content as "application/octet-stream", where as API call wants the content type as "application/vnd.qlik.sense.app". Many posts in internet says that HttpPostedFileBase is a read only and we cannot change the content type.

推荐答案

您是否尝试过添加 application / vnd。 qlik.sense.app 作为web.config文件中的mime类型?这样的事情:



Have you tried adding application/vnd.qlik.sense.app as a mime type in your web.config file? Something like this:

<System.webServer>
    <staticContent>
        <remove fileExtension=".sense.app" />
        <mimeMap fileExtension=".sense.app" mimeType="qlik_sense_app" />
    </staticContent>
</system.webServer>





您可能需要从 fileExtension 属性,因为如果IIS可以使用该格式,我现在还没有。



You may have to remove ".sense" from the fileExtension attribute, because I don't now right off hand if that format is usable by IIS.


这篇关于如何更改httppostedfilebase的内容类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆