简体   繁体   English

Content-Transfer-Encoding in file upload request

[英]Content-Transfer-Encoding in file uploading request

I'm trying to upload file, using XMLHTTPRequest, and sending this headers: 我正在尝试使用XMLHTTPRequest上传文件,并发送此标头:

Content-Type:multipart/form-data, boundary=xxxxxxxxx

--xxxxxxxxx
Content-Disposition: form-data; name='uploadfile'; filename='123_logo.jpg'
Content-Transfer-Encoding: base64
Content-Type: image/jpeg
/*base64data*/

But on server side PHP ignore header "Content-Transfer-Encoding: base64" and write base64 undecoded data directly into the file! 但是在服务器端PHP忽略标题“Content-Transfer-Encoding:base64”并将base64未解码的数据直接写入文件!

Is there any way to fix it? 有什么办法可以解决吗?

ps it is very important to send data using base64 ps使用base64发送数据非常重要

Xavier's answer doesn't sound right. 泽维尔的回答听起来不对。 RFC2616 also has this to say (section 3.7): RFC2616也有这个说法(第3.7节):

In general, HTTP treats a multipart message-body no differently than 通常,HTTP对多部分消息体的处理方式与此不同
any other media type: strictly as payload. 任何其他媒体类型:严格作为有效载荷。 The one exception is the 唯一的例外是
"multipart/byteranges" “多/字节范围”

It seems to me that section 19.4 of RFC2616 is talking about HTTP as a whole, in the sense that it uses a syntax similar to MIME (like headers format), but is not MIME-compliant. 在我看来,RFC2616的第19.4节正在讨论HTTP作为一个整体,在某种意义上它使用类似于MIME的语法(如头格式),但符合MIME。

Also, there is RFC2388 . 此外,还有RFC2388 In section 3 , last paragraph, it says: 第3节 ,最后一段,它说:

Each part may be encoded and the "content-transfer-encoding" header 可以对每个部分进行编码,并对“内容传输编码”头部进行编码
supplied if the value of that part does not conform to the default 如果该部分的值不符合默认值,则提供
encoding. 编码。

Section 4.3 elaborates on this: 第4.3节详细阐述了这一点:

4.3 Encoding 4.3编码

While the HTTP protocol can transport arbitrary binary data, the default for mail transport is the 7BIT encoding. 虽然HTTP协议可以传输任意二进制数据,但邮件传输的默认值是7BIT编码。 The value supplied for a part may need to be encoded and the "content-transfer-encoding" header supplied if the value does not conform to the default encoding. 如果值不符合默认编码,则可能需要对为部件提供的值进行编码并提供“content-transfer-encoding”头。 [See section 5 of RFC 2046 for more details.] [有关详细信息,请参阅RFC 2046的第5节 。]

My previous answer was wrong 我之前的回答是错的

Content-Transfer-Encoding may appear in the a composite body Content-Transfer-Encoding可能出现在复合体中

http://www.ietf.org/rfc/rfc2616.txt http://www.ietf.org/rfc/rfc2616.txt

There are several consequences of this. 这有几个后果。 The entity-body for composite types MAY contain many body-parts, each with its own MIME and HTTP headers (including Content-MD5, Content-Transfer-Encoding, and Content-Encoding headers). 复合类型的实体主体可以包含许多主体部分,每个主体部分都有自己的MIME和HTTP头(包括Content-MD5,Content-Transfer-Encoding和Content-Encoding头)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM